Amarja Amarja - 6 months ago 11
SQL Question

How to edit form with data from database tables in laravel

I am doing project in laravel. I want edit form with database table values.

In controller,

$event_note = DB::table('event_note')->where('event_id',$id)->first();

I have blade.php file for particular textarea as,

<div class="form-group clearfix{{ $errors->has('event_note') ? ' has-error' : '' }}">
<label class="col-md-4 control-label">Note</label>
<div class="col-md-6">
<textarea class="form-control" name="event_note" rows="4" cols="50">{{ $event_note->note }}</textarea>

@if ($errors->has('event_note'))
<span class="help-block">
<strong>{{ $errors->first('event_note') }}</strong>

but as event_note doesn't have any record it throws an error as,

Trying to get property of non-object (View:....

for variable $event_note->note.

I don't know how to edit this form if database table dont have any value it should show an empty textarea.


You can use or '' clause:

{{ $event_note->note or '' }}

It's a Blade shortcut for this solution:

{{ isset($event_note->note) ? $event_note->note : '' }}