Trying to get property of non-object - Laravel Form -
i creating form many-many relationship. have posts table , activities table. there many many link using pivot table. creating form add 1 or more activities posts. receiving 'errorexception' - trying property of non-object. cannot understand why not working.
i grateful assistance can offer me.
my relevant code below.
//posts/create.blade.php {!!form::open(['action' => 'postcontroller@store','method' => 'post', 'class'=>'form-group'])!!} {{form::bstext('title','',['placeholder' => 'trip name'])}} {{form::bstextarea('body','',['placeholder' => 'trip description'])}} {{form::bssubmit('submit')}} {{form::label('activities', 'activity:') }} <select class="form-control select2-multi" name="activities" multiple="multiple"> @foreach($activities $activity) <option value="{{ $activity->id }}">{{ $activity->activity_name}} </option> @endforeach </select> {!! form::close() !!}
// postscontroller
public function create() { $activities = activity::all(); return view('posts.create')->withactivities($activities); $posts = post::all(); } public function store(request $request) { // create new post using request data // save database $this->validate(request(), [ 'title' => 'required', 'body' => 'required', ]); $post = post::create([ 'title' =>request('title'), 'body' =>request('body'), 'user_id' => auth()->id(), 'activity_id' => id() ]); // , redirect somewhere in application return redirect()->route('posts.show', $post->id); }
this error throw when have empty variable point in blade file render / display browser. or if retrieve records db add findorfail in query prevent kind of issues. thank you.
Comments
Post a Comment