Ad
Laravel: How To Check If Data In Datatables Is Valid Or Not?
I am trying to get a data from another table through foreign key, i want to check if that data is valid or not, i mean is it empty or not.
for example if the foreing key data is empty, i want to return the null.
here is what i tried to get it right but not nothing works fine if the foreign key is empty.
and here is the relationship between the two tables
public function driver()
{
return $this->belongsTo(Driver::class, 'Driver_id');
}
And again i want to clear my point i want to check if the foreign key data is empty or not, if empty i want return null.
Ad
Answer
Just check if the Driver_id is set.
$driverName = null;
if(isset($bus->Driver_id) && $bus->driver && $bus->driver->first_name) $driverName = $bus->driver->first_name.' '.$bus->driver->last_name.' '.$bus->driver->third_name;
return $driverName;
Ad
source: stackoverflow.com
Related Questions
- → OctoberCMS - How to make collapsible list default to active only on non-mobile
- → How to update data attribute on Ajax complete
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → Octobercms Component Unique id (Twig & Javascript)
- → when i send data with ajax(jquery) i don't find the values in controller without form in laravel 5.1
- → DropzoneJS & Laravel - Output form validation errors
- → Knockout JS - How to return empty strings for observable fields
- → How to replace *( in a string
- → Get the calling element with vue.js
- → Sent Variable to Controller via Ajax in Blade
- → AJAX folder path issue
- → Onclick with argument causes javascript syntax error
- → KNockout JS - Automatic reload of ajax call
Ad