I have table contain id, customer_id,..etc so findOrFail will work only for id so want to check customer_id record not id. How can I check other record using findOrFail something like this
$post = Customer::findOrFail('customer_id',$request->customer_id)
Maybe you are looking for firstOrFail()
, so you can do:
Customer::whereCustomerId($request->customer_id)->firstOrFail();
findOrFail()
only works for the primary key id
so you have to use firstOrFail
.
Note that you could also write it as:
Customer::where('customer_id', $request->customer_id)->firstOrFail();
You can use any column of a table
Customer::where('<any column>', <column value>)->firstOrFail();
Laravel example
$model = App\Flight::findOrFail(1);
$model = App\Flight::where('legs', '>', 100)->firstOrFail();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.