i get error when i send request in post man
the error:
ErrorException: Undefined array key "value" in file
thw code:
public function search(Request $request) {
$request = $request->all();
$models = Course::query()
->where('title', 'like', '%' . $request['value'] . '%')
->where(['deleted' => '0'])
->get();
return response()->json($models);
}
3
Answers
Dump out your
$request
and have a look at it, like :You probably want to access the values like :
instead of trying to access it as an array.
you can make the following changes , so that it works dynamically based on the given
here we have when statement to check whether this key exist or not , in case of non existence it won’t execute with that particular key else it works as desired.
you can also modify when statement, or if you want more conditional statement than you can also append those inside the above-mentioned statement.
del one line and use
like that