Francisunoxx Francisunoxx - 1 year ago 71
PHP Question

Is isEmpty() method is applicable for $request?

Is it possible to use

method for validating a input a for empty field? I have a
where it has a multiple form to be filled up. I have additional form where it's not totally required.


'title' => 'required|regex:/(^[A-Za-z0-9 ]+$)+/|max:255',
'content' => 'required',
'category' => 'required',
'approver' => 'required',
'recipient' => 'required',

$document = new Document();
$user = Auth::user();
//Request in the form
$document->title = $request->title;
$document->content = $request->content;
$document->category_id = $request->category;

foreach($request->recipient as $recipientId)
$document->sentToUsers()->sync([ $recipientId => ['sender_id' => $user->id]],false );

I have a form name
which is not required to be filled out. I'm trying to check if it's not empty it will insert this into database. If empty nothing will happen.

foreach($request->department as $departmentId)
foreach(Department::find($departmentId)->users()->get() as $user1) //find the users belonging to the current department
$document->sentToUsers()->sync([ $user1->id => ['sender_id' => $user->id]],false );


Answer Source

You can always use empty():


I guess isEmpty() is for collection only and you're checking property of Request object:

The isEmpty method returns true if the collection is empty; otherwise, false is returned

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download