ziben69

ziben69

Member Since 4 Months Ago

Experience Points 1,500
Experience
Level
Lessons Completed 0
Lessons
Completed
Best Reply Awards 0
Best Answer
Awards
  • Start Your Engines Achievement

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • First Thousand Achievement

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • One Year Member Achievement

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • Two Year Member Achievement

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • Three Year Member Achievement

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • Four Year Member Achievement

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • Five Year Member Achievement

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • School In Session Achievement

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • Welcome To The Community Achievement

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • Full Time Learner Achievement

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • Pay It Forward Achievement

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • Subscriber Achievement

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • Laracasts Evangelist Achievement

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • Chatty Cathy Achievement

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • Laracasts Veteran Achievement

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • Ten Thousand Strong Achievement

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • Laracasts Master Achievement

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • Laracasts Tutor Achievement

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • Laracasts Sensei Achievement

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • Top 50 Achievement

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

10 Dec
1 day ago

ziben69 left a reply on Hide If File Doesn't Exist

@SERGIU17 - That's it. Thanks

ziben69 started a new conversation Hide If File Doesn't Exist

Hello guys, I have file.blade.php.

I need to hide empty files records in view:

 <div class="row">
      @foreach($files as $file)
      <div class="col-md-4" style="margin-bottom:10px;">
             <div class="card">
                     <div class="card-body">
                            <strong>{{ $file->title }}</strong>
                            <p class="card-text">
                                    {{ $file->created_at->diffForHumans() }}
                            </p>
                            <a href="{{ route('downloadSenior', $file->id) }}"><i class="fa fa-download" aria-hidden="true"></i> Download</a>
                     </div>
             </div>
      </div>
      @endforeach
</div>

How can I hide this part of view when file doesn't exist. Now I have empty links because in my DB are 30 rows without files. I should change:

$file->id

?? Thanks for help!

06 Dec
5 days ago

ziben69 started a new conversation Existing Laravel's Project On DirectAdmin Server

Hello guys, I neet to upload project on server with DirectAdmin, so I did:

  1. Upload project to public_html
  2. I moved files from the public folder to a level earlier
  3. I put the rest of the files in a different folder.
  4. I changed the paths in index.php
  5. I changed .env file
  6. I changed PHP version on server

Wouala! Index.php works, but subpages no.

I have tried the clear: cache and other commands from web.php Still nothing.

I have error, when I try go to subpages example www.domain.com/contact:

404
Not Found
The resource requested could not be found on this server!

What more can I do? Thanks so much.

04 Dec
1 week ago

ziben69 left a reply on Download File From Database (storage)

Ok I changed method move to storeAs. Now I have good file in directory named testfile.pdf, but still have problem with download:

File not found at path: C:/xampp/htdocs/tbg/storage/app/public/files/["testfile.pdf"]

probably because filename is an array, should I decode or sth?

ziben69 left a reply on Download File From Database (storage)

Oh thats it but now I have other error:

File not found at path: C:/xampp/htdocs/tbg/storage/app/public/files/["testfile.pdf"]

in storage/app/public/files directory I have file named "php37B4.tmp"

whaaat?

ziben69 started a new conversation Download File From Database (storage)

Hello guys,

I did multiple file upload: model File:

class File extends Model
{
    protected $fillable = [
        'title',
        'description',
        'filename'
    ];
}

FileController (store function):

  public function storeFiles(Request $request)
    {

        $this->validate($request, [
            'filename' => 'required',
            'filename.*' => 'mimes:doc,pdf,docx,zip'
        ]);


        if($request->hasfile('filename'))
        {
            foreach($request->file('filename') as $file)
            {
                $name=$file->getClientOriginalName();
                $file->move(storage_path('/app/public/files/', $name));
                $data[] = $name;  
            }
        }

        $file = new File();
        $file->title = $request->input('title');
        $file->description = $request->input('description');
        $file->filename=json_encode($data);   
        $file->save();

        return redirect()->action('[email protected]');
    }

and how can I download file now. I have something like this:

public function show($id)
    {
        $dl = File::find($id);
        return Storage::download(storage_path('app/public/files/'), $dl->filename);      
    }

but it gives to me error:

File not found at path: C:/xampp/htdocs/tbg/storage/app/public/files

and URL: http://localhost/filess/download/8

Can someone help me? Thanks

ziben69 left a reply on Store Multiple Files - Access Denied

Solved: the store function tried to save the file in the files directory located in the view folder. For others: do not call the view folder: files

ziben69 left a reply on Store Multiple Files - Access Denied

@LOSTDREAMER_NL - Still the same. Prohibited access :/

ziben69 started a new conversation Store Multiple Files - Access Denied

Hello guys, I try to do multiupload files. I have model File:

class File extends Model
{
    protected $fillable = [
        'title',
        'description',
        'filename'
    ];
}

FileController (function storeFiles):

public function storeFiles(Request $request)
    {

        $this->validate($request, [
            'filename' => 'required',
            'filename.*' => 'mimes:doc,pdf,docx,zip'
        ]);

        if($request->hasfile('filename'))
        {
            foreach($request->file('filename') as $file)
            {
                $name=$file->getClientOriginalName();
                $file->move(public_path().'/files/', $name);  
                $data[] = $name;  
            }
        }

        $file = new File();
        $file->title = $request->input('title');
        $file->description = $request->input('description');
        $file->filename=json_encode($data);   
        $file->save();

        return redirect()->action('[email protected]');
    }

and form:

 <form action="{{ action ('[email protected]')}}" method="POST"
                          enctype="multipart/form-data">
<input type="hidden" name="_token" value="{{csrf_token() }}"/>
<div class="form-group" style="position:relative">
         <input type="text" class="form-control" name="title" placeholder="Title" id="title" ><div id="headercount">255</div></span>
</div>
<div class="form-group" style="position:relative">
       <textarea class="form-control" rows="5" name="description" id="description"  placeholder="Description" maxlength="999" ></textarea>
</div>
<div class="form-group">
       <input type="file" id="filename" onchange="ValidateSize(this)" name="filename[]" multiple aria-describedby="fileHelp"/>
</div>
</form>

When I try to add a file, I get an error:


Prohibited access!
You do not have the right to access the desired directory. There is no index in the catalog or the catalog is protected against reading.

If you think this is a server error, please contact your administrator.

Error 403
localhost
Apache/2.4.33 (Win32) OpenSSL/1.1.0h PHP/7.2.6

I did:

php artisan storage:link

but it still doesn't work. Can you help me? Thanks.

03 Dec
1 week ago

ziben69 started a new conversation Search | How To Get Data From All Tables, Not Only One.

Hello guys,

I have function search:

public function search(Request $request)
    {
        $search = $request->get('search');
        $queries = DB::table('articles')->where('header', 'like', '%'.$search.'%')->paginate(5);
        return view('pages.search', ['queries' => $queries]);
    }

How can I take more data? Now I have data from only articles table, but need in the same search for example users -> name. Thanks

02 Dec
1 week ago

ziben69 left a reply on Displaying Data From The Table In All Views

Ok I did it! :)

Answer: view()->composer('*', function($view){ $current = Carbon::now(); $view->with('cal', Calendar::has('photos')->with('photos')->where('date','>=',$current)->orderBy('date', 'asc')->take(3)->get()); });

just changed 'pages.rollers.rollers' to '*'. It Works :)

ziben69 left a reply on Displaying Data From The Table In All Views

Ok, so I added in AppServiceProvider:

<?php

namespace App\Providers;

use App\Calendar;

use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\View;

class AppServiceProvider extends ServiceProvider
{
    public function boot()
    {
        view()->composer('rollers.rollers', function($view){
            $view->with('cal', Calendar::has('photos')->with('photos')->where('date','>=',$current)->orderBy('date', 'asc')->take(3)->get());
        });
    }

    public function register()
    {
        //
    }
}

something like this, but it still doesn't work.

What I do step by step:

  1. include rollers.blade.php in template.blade.php
@include('pages.rollers.rollers')
  1. Add view() in AppServiceProvider
  2. After click on contact.blade.php in Google Chrome I still have error:
Undefined variable: cal (View: C:\xampp\htdocs\tbg\resources\views\pages\rollers\rollers.blade.php)

In roller.blade.php I have something like this:

@foreach($cal as $calendar)
        <li><a href="{{ URL::to('calendar') }}"><b>{{ $calendar->header }}</b> <small>- {{ $calendar->date }}</small></a></li>
@endforeach

Someone can tell me what I do wrong?

ziben69 started a new conversation Displaying Data From The Table In All Views

Hello guys, i try to display data from one table in all views, but writing in each controller is very breakneck.

I created a view in which I display data from another table. I have displayed it in the template with include ('view'), but now that I pass between subpages, it throws an error with an unknown variable. Classic :/

rollers.blade.php:

<!-- Calendar's Roll (right) -->
       @foreach($calendars as $calendar)
       <li><a href="{{ URL::to('calendar') }}"><b>{{ $calendar->header }}</b> <small>- {{ $calendar->date }}</small></a></li>
       @endforeach

RollersController:

 public function index(CalendarRepository $calRepo)
    {
        $current = Carbon::now();
        $calendars = Calendar::has('photos')->with('photos')->where('date','>=',$current)->orderBy('date', 'asc')->take(3)->get();        
        return view('pages.rollers.rollers', compact('calendars'));
    }

template.blade.php

@include('pages.rollers.rollers')

I need do something like global variable? How can I solve this?

25 Nov
2 weeks ago

ziben69 left a reply on How To Secure File Uploads

@JAYTEE - If I change rules to:

return [
    'photos.*' => 'image|mimes:jpeg,bmp,png|max:2000',
    'header' => 'required|max:255',
    'description' => 'required',
    'date' => 'required',
]

I have the same:

No message

and I can upload nothing:

Class App\Http\Requests\UploadRequest does not exist

or I think wrong

ziben69 started a new conversation How To Secure File Uploads

Hello guys I have done tutorial to upload image files from link: https://laraveldaily.com/upload-multiple-files-laravel-5-4/

But how can I secure file uploads in view. Something like communicate when user will upload file more than 2MB?

Fragment of create.blade.php:

 <div class="form-group">
        <input type="file" name="photos[]" multiple aria-describedby="fileHelp"/>
        <small id="fileHelp" class="form-text text-muted">jpeg, png, bmp - 2MB.</small>
 </div>

and rules:

public function rules()
    {
        $rules = [
            'header' => 'required|max:255',
            'description' => 'required',
            'date' => 'required',
        ];
        $photos = $this->input('photos');
        foreach(range(0, $photos) as $index) {
            $rules['photos.' . $index] = 'image|mimes:jpeg,bmp,png|max:2000';
        }
 
        return $rules;
    }

all ok but when I try now to upload file which have got more than 2MB it gives me error:

Illuminate \ Http \ Exceptions \ PostTooLargeException
No message

How can I solve this? Thanks for help.

24 Nov
2 weeks ago

ziben69 left a reply on Save Calendar's Event With Photo (two Tables)

@RONALDJESSE - It work but not correct :P

i have 5 photos in Photo table, and when I create new calendar event it should create new record in Table Calendar and Table Photo with calendar_id. Now after click on button save it is editing existing record, and it is changing his calendar_id, but it should create new record in table with new calendar_id

23 Nov
2 weeks ago

ziben69 left a reply on Save Calendar's Event With Photo (two Tables)

I get photos in CalendarController function create, but how to store them in photo table which is in relationship with Calendar table

ziben69 started a new conversation Save Calendar's Event With Photo (two Tables)

Hello guys, I have a problem saving the photo when creating a calendar event. I have two tables in relationship calls: model Calendar

class Calendar extends Model
{
    protected $fillable = [
        'header','description','date'
    ];
    
      public function photos()
    {
        return $this->hasMany(Photo::class);   
    }

and model Photo: class Photo extends Model { protected $fillable = [ 'photoable_type','photoable_id','path','calendar_id' ];

public function calendar()
{
    return $this->belongsTo(Calendar::class, 'calendar_id');
}

}

my photos have calendar_id, i.e. one event can have many photos.

Here is CalendarController (create and store functions):

  public function create()
    {

        $photos = Photo::all();
        return view('pages.calendar.create', [
            "photos" => $photos
        ]);
    }

    public function store(Request $request)
    {
        $request->validate([
            'header' => 'required|max:255',
            'description' => 'required',
            'date' => 'required',
        ]);

        $calendar = new Calendar();
        $calendar->calendar_id = $request->input('photo'); <--- calendar_id is in the photo model
        $calendar->header = $request->input('header');
        $calendar->description = $request->input('description');
        $calendar->date = $request->input('date');
        $calendar->save();
    
        return redirect()->action('[email protected]');
    }

and here is a fragment of create.blade.php view:

<form action="{{ action ('[email protected]')}}" method="POST"
                          enctype="multipart/form-data">
                        <input type="hidden" name="_token" value="{{csrf_token() }}"/>
                        <div class="form-group">
                            <label for="photo">Photo:</label> <select class="form-control"
                                                                     name="photo"> 
                            @foreach($photos as $photo)
                            <option value="{{ $photo->id }}"><img class="img-responsive" src="{{ $photo->path }}"  style="width:100px; height:auto;"/></option>
                            @endforeach
                            </select>
                        </div>
                        <div class="form-group">
                            <label for="header">Header</label> <input type="text"
                                                                      class="form-control" name="header"/>
                        </div>
                        <div class="form-group">
                            <label for="description">Description</label><input type="text"
                                                                               class="form-control" name="description"/>
                        </div>
                        <div class="form-group">
                            <label for="date">Date</label> <input type="date"
                                                                  class="form-control" name="date"/>
                        </div>
                        <input type="submit" value="Create" class="btn btn-primary"/>
                    </form>

Error:

Column not found: 1054 Unknown column 'calendar_id' in 'field list' (SQL: insert into `calendars` (`calendar_id`, `header`, `description`, `date`, `updated_at`, `created_at`) values (204, asdsa, dsadsaasd, 1998-12-12, 2018-11-23 11:21:09, 2018-11-23 11:21:09))

I know that calendar_id is a column in Photo table, but how can I solve this?? I need to add photos from calendar's create view. Thanks for help.

22 Nov
2 weeks ago

ziben69 left a reply on Display One Photo For One Calendar's Event.

@BAHJAAT - Sorry, I forget about models. Edited

ziben69 started a new conversation Display One Photo For One Calendar's Event.

Hello guys, How can I display one photo in relationship with calendar?

Now I am displaying all photos:

  1. CalendarController.php:
class CalendarController extends Controller
{
    public function index(CalendarRepository $calRepo)
    {
        $calendars = Calendar::has('photos')->with('photos')->get();

        return view('pages.calendar.calendar', compact('calendars'));
    }
}
  1. calendar.blade.php
@foreach($calendars as $calendar)
    @foreach($calendar->photos as $photo)
        <img class="img-responsive" src="{{ $photo->path }}"/>
    @endforeach
@endforeach

It gives me in result list of photos from all calendar's events. I need to display only one photo for one calendar's event - but for all events from calendars table.

Thanks so much!

21 Nov
2 weeks ago

ziben69 left a reply on Get All Photos From Table Photos, And Display Them In Relationship Calendar's View

@signar can you tell me how can I display now only one photo for one event?

Now I have all photos of all events.

I need do something like a blog, first photo, and after click on link all photos from event. Thanks

ziben69 left a reply on Get All Photos From Table Photos, And Display Them In Relationship Calendar's View

When I want to display in view photos like a:

@foreach ($calendar as $calendar)
    {{ $calendar->photo }}
@endforeach

[{"id":204,"photoable_type":"App\Calendar","path":"https://lorempixel.com/800/400/city/?37194","calendar_id":1},

I got objects (array) with data about photos. When I add "path" to loop

{{ $calendar->photo->path }}

i have error: Property [path] does not exist on this collection instance.

Can you help?

ziben69 started a new conversation Get All Photos From Table Photos, And Display Them In Relationship Calendar's View

Hello guys, I have 2 tables: photos and calendars:

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Calendar extends Model
{
    protected $fillable = [
        'header','description','date'
    ];

    
      public function photos()
    {
        return $this->hasMany(Photo::class);   
    }
   
}

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Photo extends Model
{
    protected $fillable = [
        'photoable_type','photoable_id','path','calendar_id'
    ];

    public function calendar()
    {
        return $this->belongsTo(Calendar::class);
    }
}

Repository:

<?php
namespace App\Repositories;

use App\Models\Calendar;

class CalendarRepository extends BaseRepository
{
    public function __construct(Calendar $model)
    {
        $this->model = $model;
    }

    public function getAllEventsWithPhoto($columns = array('*')){
        return $this->model->with('photos')->get($columns);
    }
    
    public function getCalendarEventWithPhoto($id){
        return $this->model->with('photos')->find($id);
    }
    
}

CalendarController

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\Calendar;
use App\Models\Photo;
use App\Repositories\CalendarRepository;
use DB;

class CalendarController extends Controller
{
    public function index(CalendarRepository $calRepo)
    {
        $calendar = $calRepo->getAllEventsWithPhoto();
        $calendar->load('Photo');
        
    
        return view('pages.calendar.calendar',[
            "calendar" => $calendar
        ]);
    }
}

and Calendar.blade.php view:


@foreach ($calendar->photo as $photo)
    <img class="img-responsive" src="{{ $photo->path }}"/>
@endforeach 

My functions from CalendarRepository.php doesn't works:

Call to undefined relationship [Photo] on model [App\Models\Calendar].

But when I am using function load() it works only with:

$calendar = $calRepo->find(1);

But I need all calendar's events with photos. Can someone help? Thanks so much

23 Aug
3 months ago

ziben69 left a reply on Generating A Pdf From An Existing Table's Record

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

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.

22 Aug
3 months ago

ziben69 left a reply on Display Data From Timeline Table In Task's View

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

But how can I display data in View :D?

ziben69 left a reply on Display Data From Timeline Table In Task's View

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

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

i have task_id inside timeline table

ziben69 left a reply on Display Data From Timeline Table In Task's View

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))

21 Aug
3 months ago

ziben69 left a reply on Display Data From Timeline Table In Task's View

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

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!

15 Aug
3 months ago

ziben69 left a reply on Paginate - Items Per Page

dd($perPage->all());

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

what should be in form action??

14 Aug
3 months ago

ziben69 left a reply on Paginate - Items Per Page

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

ziben69 left a reply on Paginate - Items Per Page

<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

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.

11 Aug
4 months ago

ziben69 left a reply on Filter Data From DB.

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.

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?

10 Aug
4 months ago

ziben69 left a reply on Filter Data From DB.

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.

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

ziben69 left a reply on Filter Data From DB.

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.

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.

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.

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.

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.

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.

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',
    ];~~~
25 Jul
4 months ago

ziben69 left a reply on File Upload To Database

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

ziben69 started a new conversation File Upload To Database

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]e');
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.