Laravel Expressive query similar to findorfail

I would like to look at and return the object referenced by another column with the name id.

As far as I know, there is no other method similar Task::findOrFail($id), but which can refer to another field. For instance:

Task::findOrFail('column_name' = 'column_data');

I am currently using

Task::where('tid' , '=', $tid)->first();

Is it possible?

+4
source share
1 answer

Perhaps you can use the firstOrFail () function of Laravel.

Task::where('column_name', '=' ,'column_data')->firstOrFail();
+17
source

Source: https://habr.com/ru/post/1535769/


All Articles