laravel

Laravel Property [title] does not exist on the Eloquent builder instance

浪子不回头ぞ 提交于 2021-01-18 12:49:51
问题 I am getting an error while trying to display data from the database.This problem occurred by other people who have created posts on this website. but they have a foreach loop and I don't. so all the answers given for this problem do not work. article controller public function showwereld($id) { $artikels = Artikel::where('id', $id); return view('pages.show')->with('artikels', $artikels); } show.blade.php <div class="row"> <div class="artikeltitel marginauto"> <div class="col-md-6 offset-md-3

Laravel collection group by

倾然丶 夕夏残阳落幕 提交于 2021-01-18 10:40:22
问题 I have a search function to search for expenses by a certain date, month, string, whatever. It returns a collection: So far so good. I can display all returned Expenses . Now, what I want to do is, display also a total expense count and total amount, grouped by the description_id . If I simply do $result->groupBy('description_id) , I just get a set of collections, from which I can display the total count and total amount, but not the name of the description. Example of what I want: Grouped

Laravel Validation check array size min and max

这一生的挚爱 提交于 2021-01-17 06:44:41
问题 I just need to check in Laravel validation that an array contains minimum 2 values and maximum 4 values. Is there any default validation rule can be used for this ? The size element checks for exact size match and the other rules likes min and max are for strings, digits and file size. 回答1: A little bit late: return [ "ticket_photo" => ["required","array","min:2","max:4"], // validate an array contains minimum 2 elements and maximum 4 "ticket_photo.*" => ["required","mimes:jpeg,jpg,png,gif"],

Laravel Validation check array size min and max

久未见 提交于 2021-01-17 06:43:40
问题 I just need to check in Laravel validation that an array contains minimum 2 values and maximum 4 values. Is there any default validation rule can be used for this ? The size element checks for exact size match and the other rules likes min and max are for strings, digits and file size. 回答1: A little bit late: return [ "ticket_photo" => ["required","array","min:2","max:4"], // validate an array contains minimum 2 elements and maximum 4 "ticket_photo.*" => ["required","mimes:jpeg,jpg,png,gif"],

Laravel Validation check array size min and max

落花浮王杯 提交于 2021-01-17 06:42:14
问题 I just need to check in Laravel validation that an array contains minimum 2 values and maximum 4 values. Is there any default validation rule can be used for this ? The size element checks for exact size match and the other rules likes min and max are for strings, digits and file size. 回答1: A little bit late: return [ "ticket_photo" => ["required","array","min:2","max:4"], // validate an array contains minimum 2 elements and maximum 4 "ticket_photo.*" => ["required","mimes:jpeg,jpg,png,gif"],

Laravel get class name of related model

半城伤御伤魂 提交于 2021-01-16 05:08:13
问题 In my Laravel application I have an Faq model. An Faq model can contain many Product models, so the Faq class contains the following function: class Faq extends Eloquent{ public function products(){ return $this->belongsToMany('Product'); } } In a controller, I would like to be able to retrieve the class name that defines the relationship. For example, if I have an Faq object, like this: $faq = new Faq(); How can I determine the class name of the relationship, which in this case would be

Laravel get class name of related model

拟墨画扇 提交于 2021-01-16 05:07:29
问题 In my Laravel application I have an Faq model. An Faq model can contain many Product models, so the Faq class contains the following function: class Faq extends Eloquent{ public function products(){ return $this->belongsToMany('Product'); } } In a controller, I would like to be able to retrieve the class name that defines the relationship. For example, if I have an Faq object, like this: $faq = new Faq(); How can I determine the class name of the relationship, which in this case would be

Laravel eager load function limit

ぃ、小莉子 提交于 2021-01-16 04:23:19
问题 I have a working function, however, I'd like to limit the number of treatments, per consultant, that are returned. Working Example: Clinic::where('user_id', Auth::id()) ->with('consultants.specialism', 'consultants.treatments') ->first(); Proposed (but not working) example: Clinic::where('user_id', Auth::id()) ->with('consultants.specialism') ->with(['consultants.treatments' => function ($query) { $query->take(3); }]) ->first(); Unfortunately, the take or limit function, limits it to the

Laravel eager load function limit

别说谁变了你拦得住时间么 提交于 2021-01-16 04:21:54
问题 I have a working function, however, I'd like to limit the number of treatments, per consultant, that are returned. Working Example: Clinic::where('user_id', Auth::id()) ->with('consultants.specialism', 'consultants.treatments') ->first(); Proposed (but not working) example: Clinic::where('user_id', Auth::id()) ->with('consultants.specialism') ->with(['consultants.treatments' => function ($query) { $query->take(3); }]) ->first(); Unfortunately, the take or limit function, limits it to the

Laravel eager load function limit

只愿长相守 提交于 2021-01-16 04:21:07
问题 I have a working function, however, I'd like to limit the number of treatments, per consultant, that are returned. Working Example: Clinic::where('user_id', Auth::id()) ->with('consultants.specialism', 'consultants.treatments') ->first(); Proposed (but not working) example: Clinic::where('user_id', Auth::id()) ->with('consultants.specialism') ->with(['consultants.treatments' => function ($query) { $query->take(3); }]) ->first(); Unfortunately, the take or limit function, limits it to the