nero's avatar
Level 1

I had a problem in the edit controller and edit view blade

I had a problem in the edit controller and edit view blade. Please hel me. The image data and the address does not appear in the form edit.blade.php. The image data is located in a public directory / uploads / events /.

Relationships using One To Many.

one event a multi address

The following piece of my script.

Table Structure:

Tabel events:

id
subject
description
image

Table event_addresss:

id
event_id
address

Event Model:

public function EventAddress(){
return $this->hasMany('App\EventAddress','event_id','id',address);
}

EventAddress Model:

public function Event(){
return $this->belongsTo('App\Event','event_id','id',address);
}

Controller Edit:

$data['event']=Event::findOrFail($id);
$event_addresss = Image::lists('address','image', 'id','event_id')->all();      
return view('event.edit',$data,compact('event_addresss'));

Edit.blade:

{!! Form::model($event,array('url'=>'event/update','files'=>'true'))!!}
{!! Form::text('id','address',$event_addresss,null,['class'=>'form- 
control','placeholder'=>trans('label.input_subject')]) !!}
{!! Form::file('image',['id'=>'input-2','class'=>'file','data-show-upload'=>'false','data-show-     
caption'=>'true','multiple'=>'true']) !!}
0 likes
3 replies
bobbybouwmann's avatar

This line is incorrect

return view('news.edit',$data,compact('event_addresss'));

You either pass an array with values or you pass the compact function to is

$data['event'] = Event::findOrFail($id);
$data['event_address'] = Image::lists('address','image', 'id','event_id')->all();

return view('news.edit', $data);

// Or use compact and nothing else
$event = Event::findOrFail($id);
$event_address = Image::lists('address','image', 'id','event_id')->all();

return view('news.edit', compact('event', 'event_address'));
nero's avatar
Level 1

Sorry Image is not a table. I've adjusted the following code. But the address data has not yet appeared. I have not tried to come up with the image that is on the table Events:

Controller:

$event = Event::findOrFail($id);
$event_address = EventAddress::lists('address'', 'id','event_id')->all();
return view('event.edit', compact('event', 'event_address'));

Code on edit.blade:

{!! Form::model($event, ['method' => 'PATCH','route' => ['event.update', $event->id]]) !!}
{!! Form::text('address',$event->address,$event->address,null,['class'=>'form- 
   control','placeholder'=>trans('label.input_subject')]) !!}
Snapey's avatar

You cannot pre-fill an input field of type 'file', and I'm not sure that you would be doing if you could?

Please or to participate in this conversation.