ziben69

Experience

640

0 Best Reply Awards

  • Member Since 1 Month Ago
  • 0 Lessons Completed
  • 0 Favorites

15th August, 2018

ziben69 left a reply on Paginate - Items Per Page • 6 days ago

dd($perPage->all());

error: Call to a member function all() on integer

what should be in form action??

14th August, 2018

ziben69 left a reply on Paginate - Items Per Page • 6 days ago

I added request, but it is still not working. Hmm

ziben69 left a reply on Paginate - Items Per Page • 6 days ago

<form class="form-inline" method="GET" role="form">
            <div class="form-group">
                            <label for="perPage">Ilość elemetów na stronie: &nbsp;</label>
                            <select class="form-control" id="perPage" name="perPage">
                                <option>5</option>
                                <option>10</option>
                                <option>15</option>
                                <option>20</option>
                                <option>25</option>
                            </select>
           </div>
</form>

ok I got it, but still not working

ziben69 started a new conversation Paginate - Items Per Page • 6 days ago

Hello guys,

I have question about items per page.

public function index(TaskRepository $taskRepo)
    {
        if(Auth::user()->type != 'admin'){
            return redirect()->route('login');
        }

        $perPage = 2;

        if(request()->has('status')) {
        $tasks = DB::table('tasks')->where('status', request('status'))->orderBy('id','asc')->paginate($perPage)->appends('status', request('status'));

        } else {
        $tasks = DB::table('tasks')->orderBy('id','asc')->paginate($perPage);
        }
        //$tasks = $taskRepo->getAll();
        return view('tasks.list', [
            "taskList" => $tasks
        ]);
    }

now I have variable $perPage =2; but how can I pass number from view to the controller on change value?

view select:

<form>
  <div class="form-group">
    <label for="perPage">Example select</label>
    <select class="form-control" id="perPage">
      <option>5</option>
      <option>10</option>
      <option>15</option>
      <option>20</option>
      <option>25</option>
    </select>
  </div>
</form>

Thanks for any help.

11th August, 2018

ziben69 left a reply on Filter Data From DB. • 1 week ago

probably that's it :) now I need to remove mails and will be good :D Thanks so much :)

ziben69 left a reply on Filter Data From DB. • 1 week ago

I need to remove all mails which include firstname and lastname in mail, for example:

if mail looks like:

john13@example.com -> remove [email protected] ->remove [email protected]>remove [email protected]>remove

if mail looks like: [email protected]> stay [email protected]> stay etc

now it removing only mails like a:

[email protected] [email protected] but [email protected] is still in table

can this be somehow covered by regular expressions?

10th August, 2018

ziben69 left a reply on Filter Data From DB. • 1 week ago

hmm it works but it choose only for example:

Firstname: john Lastname: doe mail: [email protected]

and it doesn't choose something like: [email protected]

ziben69 left a reply on Filter Data From DB. • 1 week ago

i don't know to fix it... Query doesn't work correct.

ziben69 left a reply on Filter Data From DB. • 1 week ago

Ops:

Symfony \ Component \ Debug \ Exception \ FatalErrorException (E_UNKNOWN) Allowed memory size of 134217728 bytes

GET http://laravel.local/mails 500 (Internal Server Error)

Haha :D

ziben69 left a reply on Filter Data From DB. • 1 week ago

Collection {#6559 ▼
  #items: array:5938 [▼
    0 => {#620 …6}
    1 => {#621 …6}
    2 => {#622 …6}
    . . .
    2498 => {#3118 …6}
    2499 => {#3119 …6}
     …3438
  ]
}

number of records in my DB = 5938 here i get the same

ziben69 left a reply on Filter Data From DB. • 1 week ago

Something wrong in first line with "as":

syntax error, unexpected 'as' (T_AS), expecting ',' or ')'

i am trying your code in function in controller.

ziben69 left a reply on Filter Data From DB. • 1 week ago

I'd love to use the subquery but I do not really understand how to construct this query.

ziben69 left a reply on Filter Data From DB. • 1 week ago

Yes, that's it :) Maybe I can better to present the problem:

i have table which include: id, firstname, lastname, email. I have ~100k personal data. I need to filter mails like this:

if mail (id 1) include firstname or lastname (still id 1) in mail = remove from view or table.

i am trying to do it in JavaScript but maybe its wrong idea, check this:

$(document).ready(function() {
    firstName = window.firstname;
    lastName = window.lastname;
    
    var names = [firstName];
    var emails = [email];
    var result = emails.filter(email => !names.find(name => email.includes(name)));
    
    console.log(result);
});

it doesn't work correct

 public function index(MailRepository $mailRepo)
    {
        JavaScript::put([
            'firstname' => $mailRepo->getFirstname(),
            'lastname' => $mailRepo->getLastname(),
            'email' => $mailRepo->getMail()
        ]);
        
        $firstNameOfMails = $mailRepo->getFirstname();
        $mails = $mailRepo->getAll();
        return view('mails.list', [
            "mailList" => $mails, "firstnameList" =>$firstNameOfMails
        ]);
    }

Can you help me do it by using subquery or just repair this what i have ;P?

ziben69 left a reply on Filter Data From DB. • 1 week ago

Ok I have got now 3 arrays from one table:

  1. Firstname, 2. Lastname, 3. Email
public function getFirstName(){
        return $this->model->get(['firstname']);
    }

public function getLastName(){
        return $this->model->get(['lastname']);
    }

public function getMails(){
        return $this->model->get(['mail']);
    }

maybe have you solution how can I make next step? Now I need remove records where mail include firstname or lastname

Thanks

ziben69 started a new conversation Filter Data From DB. • 1 week ago

Hello guys,

my question is about laravel, eloquent filtering. I have table which have got records: id, firstname, lastname, email.

I know how to display all informations from table, but how can I modify it to this:

Display all e-mails that don't contain firstname and lastname. Something like this:

Table: personal_data firstname lastname email john doe [email protected] dennis rat [email protected] mia donut [email protected]

and i need to have result:

Result: [email protected]

rest of data to the trash. Can someone help me?

public function index(MailRepository $mailRepo)
    {
        $mails = $mailRepo->getAll();
        return view('mails.list', [
            "mailList" => $mails
        ]);
    }~~~

~~~MailRepository:
protected $model;

    public function getAll($columns = array('*'))
    {
        return $this->model->get($columns);
    }~~~

~~~ Mail model:
protected $fillable = [
        'FirstName', 'LastName', 'Email',
    ];~~~

25th July, 2018

ziben69 left a reply on File Upload To Database • 3 weeks ago

Thanks for really quick answer. It help :D :* and it WORKS ! :)

ziben69 started a new conversation File Upload To Database • 3 weeks ago

Hello guys,

i am trying to do file upload system. When I click on the button, nothing happens. Can someone help me?

View's form:

<form action="{{ action ('[email protected]')}}" method="POST" enctype="multipart/form-data">
                    <input type="hidden" name="_token" value="{{csrf_token() }}" />
                    <div class="form-group">
                        <label>File:</label> <input type="file"
                            class="form-control" name="billcover" />
                    </div>
                    <input type="submit" value="Dodaj" class="btn btn-primary" />
                </form>

Controller's methods:

use Illuminate\Http\Request;
use App\Models\Bill;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\File;
. . .

public function create()
    {
        return view('bills.create');
    }
      
    public function store(Request $request)
    {
        request()->validate([
            'name' => 'required',
        ]);
        $cover = $request->file('billcover');
        $extension = $cover->getClientOriginalExtension();
        Storage::disk('public')->put($cover->getFilename().'.'.$extension,  File::get($cover));
        
        $bill = new Bill();
        $bill->name = $request->name;
        $bill->mime = $cover->getClientMimeType();
        $bill->original_filename = $cover->getClientOriginalName();
        $bill->filename = $cover->getFilename().'.'.$extension;
        $bill->save();
        
        return redirect()->route('bills.index')
        ->with('success','Bill added successfully...');
    }
. . .

Model:

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Bill extends Model
{
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'filename', 'mime', 'original_filename',
    ];
    
    public function user()
    {
        return $this->belongsTo(User::class);
    }
}

Routing:

Route::get('bills/create', '[email protected]');
Route::post('bills/', '[email protected]');

and filesystems.php:

 'public' => [
            'driver' => 'local',
            'root'   => public_path() . '/uploads',
            'url' => env('APP_URL').'/public',
            'visibility' => 'public',
        ],

It should store files in database Bill table, and in directory "public/uploads", nothing there after click on Submit. Null of errors. After clicked on button just page refresh.

23rd July, 2018

ziben69 left a reply on How To Convert Date Fields To Timestamps And Substract Them? • 4 weeks ago

so much thanks, it works!

ziben69 left a reply on Pass Database Data Eloquent To JavaScript File And Send Result To The View • 4 weeks ago

I used this movie:

https://www.youtube.com/watch?v=EttuAGYJ_so

it works great, but thanks for any answers guys.

:*

ziben69 left a reply on Pass Database Data Eloquent To JavaScript File And Send Result To The View • 4 weeks ago

Ok i am sending data to view like example {{ $name }}. But how can I send this to the code.js file

ziben69 started a new conversation Pass Database Data Eloquent To JavaScript File And Send Result To The View • 4 weeks ago

Hello guys,

can you tell me how can I pass database data from laravel to JavaScript and from Javascript to the view?

I have table Task with column Date, and I would like to send them to JavaScript. I need calculate difference of dates.

Thanks so much

ziben69 left a reply on How To Convert Date Fields To Timestamps And Substract Them? • 4 weeks ago

i have JS file:

window.onload = (function() {
  var current_progress = 0;
  
  var interval = setInterval(function() {
      current_progress += 10;
      $("#dynamic")
      .css("width", current_progress + "%")
      .attr("aria-valuenow", current_progress)
      .text(current_progress + "% Complete");
      if (current_progress >= 100)
          clearInterval(interval);
  }, 1000);
});

but its only example, it work. Dont know how to pass eloquent to javascript file

ziben69 left a reply on How To Convert Date Fields To Timestamps And Substract Them? • 4 weeks ago

Yep i am using Eloquent.

ziben69 started a new conversation How To Convert Date Fields To Timestamps And Substract Them? • 4 weeks ago

Hello guys,

I have question, maybe you can help me.

I have two fields in table Task:

startDate, stopDate

How can i convert to the timestamps and substract them. I need one field with, something like: deadline field?

I have MVC standard in my project. So much thanks :*

20th July, 2018

ziben69 left a reply on Date Progress Bar - Laravel 5+, Bootstrap 4 • 1 month ago

Can you help me? I am new programmer and I dont know how to use database's variables in JavaScript. In the view I know how to display them, but how to pass to javascript?

ziben69 started a new conversation Date Progress Bar - Laravel 5+, Bootstrap 4 • 1 month ago

Hello all,

can you help me with progress bar?

I have two columns: startDate, endDate, and progress bar from Bootstrap 4:

      $table->date('startDate');
      $table->date('endDate');

how can I set startDate like a minValue, and endDate like a maxValue, and step like one day? I would like to start bar with the start date. Thanks.

18th July, 2018

ziben69 left a reply on Laravel 5 - How To Display Data From Database For A Specific User From Other Table • 1 month ago

Sorry for newbie questions, but i am just testing laravel. I'm new here :D

ziben69 left a reply on Laravel 5 - How To Display Data From Database For A Specific User From Other Table • 1 month ago

It work but i have


Collection {#586 ▼
  #items: array:3 [▼
    0 => Task {#582 ▶}
    1 => Task {#583 ▶}
    2 => Task {#584 ▶}
  ]
}

on screen :D

ziben69 left a reply on Laravel 5 - How To Display Data From Database For A Specific User From Other Table • 1 month ago

Look at this, now i have:

Models:

//Task
 public function user()
    {
        return $this->belongsTo('App\Models\User');
    }

//User
  public function task()
    {
        return $this->hasMany('App\Models\User');
    }

BaseRepository;

abstract class BaseRepository
{

    protected $model;

    public function getAll($columns = array('*'))
    {
        return $this->model->get($columns);
    }

    public function create($data)
    {
        return $this->model->create($data);
    }

    public function update($data, $id)
    {
        return $this->model->where("id", "=", $id)->update($data);
    }

    public function delete($id)
    {
        return $this->model->destroy($id);
    }

    public function find($id)
    {
        return $this->model->find($id);
    }
}

TaskController:

    public function index(TaskRepository $taskRepo)
    {
        $tasks = $taskRepo->getAll();
        return view('tasks.list', [
            "taskList" => $tasks
        ]);
    }
    
    public function showByUserId(Task $task)
    {
        return view('tasks.showByUserId', [
            "task" => $task]);
        
    }

View:

@foreach($task as $task)

{{ dd(Auth::user()->task) }}

@endforeach

I need to display a list of tasks for the logged user (user with id) in the Task table I have user_id

ziben69 left a reply on Laravel 5 - How To Display Data From Database For A Specific User From Other Table • 1 month ago

Maybe I should show you my code?

ziben69 left a reply on Laravel 5 - How To Display Data From Database For A Specific User From Other Table • 1 month ago

Oh, maybe we did not understand. I want to display tasks from Task table, but not all. Only tasks belonging only to the logged-in user.

ziben69 left a reply on Laravel 5 - How To Display Data From Database For A Specific User From Other Table • 1 month ago

Hello, thanks for answers. In both cases I get a result in the form of NULL. I have in Task table records with user_id

@extends('template') @section('content')

{{ dd(Auth::user()->tasks) }}

{{ dd($task->user) }}

@endsection('content')

^ it doesn't work :/

ziben69 started a new conversation Laravel 5 - How To Display Data From Database For A Specific User From Other Table • 1 month ago

I want to show data from a database that is about a specific user.

I have 2 tables: users and tasks. Table users is installed from php artisan make:auth. In Table tasks I have user_id, and its foreign key:

public function task(){ return $this->belongsTo(Task::class,'user_id'); }

In controller i have got methods:

public function index(TaskRepository $taskRepo) { $tasks = $taskRepo->getAll(); return view('tasks.list', [ "taskList" => $tasks ]); }

public function show(TaskRepository $taskRepo, $id)
{
    $task = $taskRepo->find($id);
    return view('tasks.show', [
        "task" => $task
    ]);
}

I would like to get help on creating a getTaskByUserId and how to display this information in a view.

Thanks for help!

Edit Your Profile
Update

Want to change your profile photo? We pull from gravatar.com.