laravel-5.4

How to use pagination along with laravel eloquent find method in laravel 5.4

一笑奈何 提交于 2020-01-05 06:25:10
问题 I am trying to implement pagination in laravel and got following error Undefined property: Illuminate\Pagination\LengthAwarePaginator::$name Here is my controller function public function showTags($id) { $tag = Tag::find($id)->paginate(5); // when lazy loading $tag->load(['posts' => function ($q) { $q->orderBy('id', 'desc'); }]); return view('blog.showtags')->withTag($tag); } Here is the Tag Model class Tag extends Model { public function posts() { return $this->belongsToMany('App\Post'); } }

Use laravel storage with Image intervention canvas()

夙愿已清 提交于 2020-01-04 01:19:20
问题 Running Laraval 5.4 with Vagrant and Homestead. Saw a few other questions regarding this issue but none provided a solution which uses the canvas() method by Intervention/Image Laravel introduced a easier storage system since 5.3 My current code: $path = $request->file('logo')->store('/clients/logos','public'); $canvas = Image::canvas($width, $height); $image = Image::make($path)->resize($width, $height, function ($constraint) { $constraint->aspectRatio(); }); $canvas->insert($image, 'center'

Can't add field from different table in laravel-backpack CRUD

拜拜、爱过 提交于 2020-01-03 01:48:05
问题 I have libraries , townships and states tables in the database ( Library , Township , State as model names). Library is 1-n to Township . In the Library . public function township(){ return $this->belongsTo('App\Township', 'township_id'); } In the Township Model public function libraries(){ return $this->hasMany('App\Library'); } And Township is 1-n to State . In the Township Model public function state() { return $this->belongsTo('App\State', 'state_id'); } In the State Model public function

Change default laravel email template theme sent to gmail or hotmail

倾然丶 夕夏残阳落幕 提交于 2020-01-02 07:27:12
问题 This is default email generated and sent by laravel using smtp , and i want to change this default template like adding some pictures,url... how can i do that? thanks 回答1: Run php artisan vendor:publish and navigate to resources/views/vendor/notifications then now you have two files, edit them. 回答2: While generating the auth using make:auth , it will generate the required views in the resources/view/auth folder. You can customize the resources/views/auth/emails/password.blade.php page as you

Laravel 5.4 View [name] not found

拈花ヽ惹草 提交于 2020-01-02 06:21:11
问题 Even if the views is available at the resources/views directory laravel is showing me this error View [name] not found. Everything was working fine until a token mismatch error occured currently i am not being able to access any view in the views directory. Route::get('/', function () { return view('welcome'); });//in web.php is throwing View [welcome] not found. exception NOTE I am running my application vagrant in homestead 回答1: First of all check welcome view exist in the resources/views

Laravel 5.4 gives Wrong COM_STMT_PREPARE response size

青春壹個敷衍的年華 提交于 2020-01-01 03:30:37
问题 I'm working on a website and it worked fine the past month, suddenly yesterday it crashed and says Wrong COM_STMT_PREPARE response size. Received 7 . This is my code in the controller: public function newsFeed() { // get all data needed for the news page try{ $news = DB::SELECT("SELECT n.newId ,n.title_en ,n.title_es ,n.description_en ,n.description_es ,n.newMainImg ,n.tags ,DATE_FORMAT(n.createDate, '%b - %e - %Y') as publishDate_en ,DATE_FORMAT(n.createDate, '%e - %b - %Y') as publishDate

How to use patch request in Laravel?

吃可爱长大的小学妹 提交于 2019-12-31 20:40:52
问题 There is entity User that is stoted in table Users Some fields in this table are null by default. I need to update these fields and set not null data. For this I try to use PATCH method in Laravel: Routing: Route::patch('users/update', 'UsersController@update'); Controller: public function update(Request $request, $id) { $validator = Validator::make($request->all(), [ "name" => 'required|string|min:3|max:50', "email_work" => 'email|max:255|unique:users', "surname" => 'required|string|min:3

How to use patch request in Laravel?

匆匆过客 提交于 2019-12-31 20:39:27
问题 There is entity User that is stoted in table Users Some fields in this table are null by default. I need to update these fields and set not null data. For this I try to use PATCH method in Laravel: Routing: Route::patch('users/update', 'UsersController@update'); Controller: public function update(Request $request, $id) { $validator = Validator::make($request->all(), [ "name" => 'required|string|min:3|max:50', "email_work" => 'email|max:255|unique:users', "surname" => 'required|string|min:3

How to format date receiving through Vuejs Datepicker in laravel

試著忘記壹切 提交于 2019-12-31 04:47:05
问题 I'm building an application in Vuejs with Laravel as backend. I'm using datepicker to add dates in column. I'm getting an error of Invalid datetime format: 1292 Incorrect datetime value: '2017-05-04T18:30:00.000Z' for column 'schedule' at row 1 I'm sending the date in request: And while doing dd in laravel I'm getting: Can someone guide me how to achieve this. 回答1: You could use Carbon to parse the date and format it accordingly $mydate = '2017-05-04T18:30:00.000Z'; // $request->schedule

Custom helper classes in Laravel 5.4

≯℡__Kan透↙ 提交于 2019-12-30 08:05:32
问题 I have some helper classes in app/Helpers . How do I load these classes using a service provider to use them in blade templates? e.g. If I have a class CustomHelper that contains a method fooBar() : <?php nampespace App\Helpers; class CustomHelper { static function fooBar() { return 'it works!'; } } I want to be able to do something like this in my blade templates: {{ fooBar() }} instead of doing this: {{ \App\Helpers\CustomHelper::fooBar() }} P.S: @andrew-brown's answer in Best practices for