ziben69

Experience

820

0 Best Reply Awards

  • Member Since 2 Months Ago
  • 0 Lessons Completed
  • 0 Favorites

23rd August, 2018

ziben69 left a reply on Generating A Pdf From An Existing Table's Record • 1 month ago

Ok I did it alone :P

Answer:

Controller function:

   public function generatePDF(TaskRepository $taskRepo, $id)
    {
        $task = $taskRepo->find($id);
        $name = $task->name;
        $description = $task->description;
        $data = ['title' => $name,
            'description' => $description
            ];
        $pdf = PDF::loadView('tasks/' . $task->$id . '/myPDF', $data);

        return $pdf->download($name . '.pdf');
    }

Route:

Route::get('/tasks/{id}/pdf','[email protected]');

View (tasks list):

<a href="{{ URL::to('/tasks/' . $task->id . '/pdf') }}">Export PDF</a>

PDF Preview View (myPDF.blade.php):

<!DOCTYPE html>
<html>
<head>
    <title>Hi</title>
</head>
<body>
    <h1>{{ $title }}</h1>
    <p>{{ $description }}</p>
</body>
</html>

i used dompdf library from: https://codebriefly.com/laravel-5-export-to-pdf-laravel-dompdf/

I hope someone will use this code to solve problems :) Greetings

ziben69 started a new conversation Generating A Pdf From An Existing Table's Record • 1 month ago

Hello,

I found tutorial in Google how to generate PDF file from view, but I need your help with generating pdf from an existing record.

I have list of tasks, and there link to generate PDF:

 <a href="{{ URL::to('/tasks/pdf') }}">Export PDF</a>

Function generatePDF:

 public function generatePDF(TaskRepository $taskRepo, $id)
    {
        $task = $taskRepo->find($id);
        $name = $task->getName();
        $data = ['title' => $name];
        $pdf = PDF::loadView('tasks/myPDF', $data);

        return $pdf->download($name . '.pdf');
    }

And route:

Route::get('/tasks/pdf','[email protected]');

i am trying something like this:

Route:
Route::get('/tasks/{id}/pdf','[email protected]');

Link in view:
 <a href="{{ URL::to('/tasks/' . $task->id . '/pdf') }}">Export PDF</a>

but it doesnt work.

How can I pass ID of existing task? Any options? Thanks so much.

22nd August, 2018

ziben69 left a reply on Display Data From Timeline Table In Task's View • 1 month ago

That's it! <3 so much thanks for help. Now time to learn myself :D

ziben69 left a reply on Display Data From Timeline Table In Task's View • 1 month ago

But how can I display data in View :D?

ziben69 left a reply on Display Data From Timeline Table In Task's View • 1 month ago

Buahahahahaha, I called the table in the singular "timeline", and should be the plural "timelines"

ziben69 left a reply on Display Data From Timeline Table In Task's View • 1 month ago

Hmm i found problem. I tried to display all the data behind the timeline table, but didn't see the table. I need fix it.

ziben69 left a reply on Display Data From Timeline Table In Task's View • 1 month ago

i have task_id inside timeline table

ziben69 left a reply on Display Data From Timeline Table In Task's View • 1 month ago

Something is wrong. Error:

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'login.timelines' doesn't exist (SQL: select * from timelines where timelines.task_id in (1))

21st August, 2018

ziben69 left a reply on Display Data From Timeline Table In Task's View • 1 month ago

I don't understand your thinking. I need to get all timeline's records for a specific task.

I have list of task and link to task details card. There I need to display timeline, now I have there only data from Task table.

ziben69 started a new conversation Display Data From Timeline Table In Task's View • 1 month ago

Hello guys,

Can you help me solve my problem? I have 2 tables: tasks and timeline. I need to display timeline data in task details card. The task table is associated with a one-to-many timeline relation table:

task model:
public function timeline()
        {
            return $this->hasMany(Timeline::class);
        }

timeline model:
public function task()
            {
                return $this->belongsTo(Task::class);
            }

i have 2 repositories: TaskRepository and TimelineRepository to get all records from tables:

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

i have TaskController with function which showing details of task:

 public function show(TaskRepository $taskRepo, $id)
    {
        if(Auth::user()->type != 'user' && Auth::user()->type != 'admin'){
            return redirect()->route('login');
        }
        
        
        $task = $taskRepo->find($id);
        return view('tasks.show', [
            "task" => $task
        ]);
    }

How can I edit this function to also return relevant records for a given task? Thanks!

15th August, 2018

ziben69 left a reply on Paginate - Items Per Page • 2 months 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 • 2 months ago

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

ziben69 left a reply on Paginate - Items Per Page • 2 months 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 • 2 months 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. • 2 months 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. • 2 months 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. • 2 months 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. • 2 months ago

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

ziben69 left a reply on Filter Data From DB. • 2 months 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. • 2 months 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. • 2 months 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. • 2 months 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. • 2 months 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. • 2 months 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. • 2 months 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 • 2 months ago

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

ziben69 started a new conversation File Upload To Database • 2 months 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? • 2 months ago

so much thanks, it works!

ziben69 left a reply on Pass Database Data Eloquent To JavaScript File And Send Result To The View • 2 months 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 • 2 months 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 • 2 months 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? • 2 months 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? • 2 months ago

Yep i am using Eloquent.

ziben69 started a new conversation How To Convert Date Fields To Timestamps And Substract Them? • 2 months 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 • 2 months 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 • 2 months 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 • 2 months 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 • 2 months 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 • 2 months 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 • 2 months 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 • 2 months 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 • 2 months 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 • 2 months 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.