Missing required parameters for [Route: messenger.store] - laravel

Why it gives an error of undefined id, i just changed Route::get to route::post and it says that id is undefined... should i change the way i pass it? is it a correct way of inserting data into database ?
here's the route
Route::post('messenger/store/{id}','MessengerController#store')->name('messenger.store');
View...
{!! Form::open(['method'=>'POST','action'=>['MessengerController#store',$id]]) !!}
<div class="form-group">
{!! Form::text('msg',null,['class'=>'form-control'])!!}
</div>
<div class="form-group">
{!! Form::submit('Send Message',['class'=>'btn btn-primary'])!!}
</div>
{!! Form::close() !!}
index controller from where i pass ID
public function index($id)
{
//
$user=Auth::user();
return view('messenger.index',compact('user','id'));
}

{!! Form::open(['method'=>'POST','action'=>['MessengerController#store',$id]]) !!}
<div class="form-group">
{!! Form::text('msg',null,['class'=>'form-control'])!!}
</div>
<div class="form-group">
{!! Form::submit('Send Message',['class'=>'btn btn-primary'])!!}
</div>
{!! Form::close() !!}
change this.
{!! Form::open(['method'=>'POST','url'=>route('messenger.store',[$id])]) !!}
<div class="form-group">
{!! Form::text('msg',null,['class'=>'form-control'])!!}
</div>
<div class="form-group">
{!! Form::submit('Send Message',['class'=>'btn btn-primary'])!!}
</div>
{!! Form::close() !!}
to this.
Using action is kind of deprecated.

Related

How do I put fill out this field in Laravel?

How do I put in my form.blade the "Please fill out this field" in every attribute?
<div class="form-group">
{!! Form::label('title','Title:'); !!}
{!! Form::text('title', null,['class'=>'form-control']); !!}
</div>
<div class="form-group">
{!! Form::label('description','Description:'); !!}
{!! Form::textarea('description', null,['class'=>'form-control']); !!}
</div>
<div class="form-group">
{!! Form::label('stock','Stock:'); !!}
{!! Form::text('stock', null,['class'=>'form-control']); !!}
</div>
<div class="form-group">
{!! Form::label('category_id','Category ID:'); !!}
{!! Form::select('category_id', $categories, null,['class'=>'form-control', 'placeholder'=>'Choose a Category']); !!}
</div>
{!! Form::submit('Save',['class'=>'btn btn-success']); !!}
Try this
<div class="form-group">
{!! Form::label('title','Title:'); !!}
{!! Form::text('title', null,['class'=>'form-control','required']); !!}
</div>
<div class="form-group">
{!! Form::label('description','Description:'); !!}
{!! Form::textarea('description', null,['class'=>'form-control','required]); !!}
</div>
<div class="form-group">
{!! Form::label('stock','Stock:'); !!}
{!! Form::text('stock', null,['class'=>'form-control','required']); !!}
</div>
<div class="form-group">
{!! Form::label('category_id','Category ID:'); !!}
{!! Form::select('category_id', $categories, null,['class'=>'form-control', 'placeholder'=>'Choose a Category','required']); !!}
</div>
{!! Form::submit('Save',['class'=>'btn btn-success']); !!}

laravel collective html form model is giving a weird case of losing the styles and layouts

i have a weird case where when i change the form::open to form::model and add $user, the page layouts are gone. by this i mean if i use below it works fine and all the layouts are perfectly there.
{!! Form::open( ['method'=>'PATCH', 'action'=>['AdminUsersController#update', $user->id], 'files'=>true , 'class'=>'form-horizontal']) !!}
but when i try to get the user details on the edit page with below code, all my layouts and styles on the edit page disappears.
{!! Form::model($user, ['method'=>'PATCH', 'action'=>['AdminUsersController#update', $user->id], 'files'=>true , 'class'=>'form-horizontal']) !!}
chrome doesnt detect any error of not able to get css files. its like laravel drops drops all of it. Below is my full code in edit page.
{!! Form::model($user, ['method'=>'PATCH', 'action'=>['AdminUsersController#update', $user->id], 'files'=>true , 'class'=>'form-horizontal']) !!}
<div class="form-group">
{!! Form::Label('name', 'Name:', ['class'=>'col-sm-3 control-label']) !!}
<div class="col-sm-9">
{!! Form::text('name', null, ['class'=>'form-control','placeholder'=>'Full Name']) !!}
</div>
</div>
<div class="form-group">
{!! Form::Label('email', 'Email:', ['class'=>'col-sm-3 control-label']) !!}
<div class="col-sm-9">
{!! Form::email('email', null, ['class'=>'form-control','placeholder'=>'user#email.com']) !!}
</div>
</div>
<div class="form-group">
{!! Form::Label('password', 'Password:', ['class'=>'col-sm-3 control-label', 'for'=>'password']) !!}
<div class="col-sm-9 strength-container">
{!! Form::password('password', ['class'=>'password-strength-example1 form-control', 'id'=>'password', 'data-plugin'=>'strength']) !!}
</div>
</div>
<div class="form-group">
{!! Form::Label('is_active', 'Active:', ['class'=>'col-sm-3 control-label']) !!}
<div class="col-sm-9">
{!! Form::hidden('is_active', 0) !!}
{!! Form::checkbox('is_active', 1, null, ['data-plugin'=>'switchery']) !!}
</div>
</div>
<div class="form-group">
{!! Form::Label('role_id', 'Role:', ['class'=>'col-sm-3 control-label']) !!}
<div class="col-sm-9">
{!! Form::select('role_id', $roles ,null, ['class'=>'form-control']) !!}
</div>
</div>
<div class="form-group form-material">
{!! Form::Label('photo_id', 'Photo:', ['class'=>'col-sm-3 control-label', 'for'=>'photo_id']) !!}
<div class="col-sm-9">
{!! Form::text('', null, ['class'=>'form-control', 'placeholder'=>'Browse..', 'readonly'=>'']) !!}
{!! Form::file('photo_id', null, ['multiple'=>'']) !!}
</div>
</div>
<div class="form-group">
<div class="col-sm-9 col-sm-offset-3">
{!! Form::submit('Submit', ['class'=>'btn btn-primary']) !!}
{!! Form::reset('Reset', ['class'=>'btn btn-danger']) !!}
</div>
</div>
{!! Form::close() !!}
and for reference. both images to see difference
Try
{!! Form::file('photo_id', ['multiple'=>'']) !!}
for file field since.

Yield a form on a different page using laravel

I'm making a twitter look-a-like app.
I have a form to post a message on 1 blade (createMessage.blade.php) which is as followed:
#section('message')
{!! Form::open(['url' => 'message/postmessage']) !!}
<div class="form-group col-lg-6 col-lg-offset-3">
{!! Form::label('body') !!}
{!! Form::textarea('body', null,['class' => 'form-control']) !!}
</div>
<div class="form-group col-lg-6 col-lg-offset-3">
{!! Form::submit('Post message', ['class' => 'btn btn-primary form-control']) !!}
</div>
{!! Form::close() !!}
#endsection`
Now I want to get my form on different pages (such as my timeline) but if I try #yield('message') it doesn't work.
timeline:
#extends('layouts.app')
#section('content')
#yield('message')
//some code for my timeline
#endsection
I can't find out why it doens't work.
Thanks in advance!
You have to use
#include('createMessage.blade.php') in the timeline file and remove the #section declaration in createMessage.blade.php

How to add bootstrap for below laravel 5 form

Below is the output of form.
I want to keep this both 2 fields in a one row. How can I do that using bootstrap? This is my view code.
{!! Form::label('titles', 'Title') !!}
{!! Form::text('title',null,['class' => 'form-control']) !!}
You can try like this:
<div class="form-group col-md-1">
{!! Form::label('titles', 'Title') !!}
</div>
<div class="form-group col-md-11">
{!! Form::text('title',null,['class' => 'form-control']) !!}
</div>

Undefined offset 0 laravel blade

I am using following route
Route::get('admin/new/password','PostController#newPasswordForm');
Route::post('admin/new/password','PostController#newPasswordStore');
and function is like this
public function newPasswordForm() {
return view('pages.posts.password');
}
and in view file this is the code
#section('content')
<div class="container bg-white">
<div class="row padding-top-80 padding-bottom-40">
<div class="col-md-12">
{!! Form::open(['url' => 'newpassword','method'=>'POST']) !!}
<div class="col-md-8">
<h2>Enter Your Password</h2>
<div class="form-group">
{!! Form::label('password', 'Password') !!}
{!! Form::password('password') !!}
</div>
<div class="form-group">
{!! Form::label('confirmpassword', 'Confirm Password') !!}
{!! Form::password('password_confirmation') !!}
</div>
<div class="clearfix"></div>
<div class="col-lg-12 text-center">
<div id="success"></div>
{!! Form::submit('Save', ['class' => 'btn btn-primary btn-large']) !!}
</div>
</div>
{!! Form::close() !!}
</div>
</div>
</div>
#endsection
but I am getting following error.
ErrorException in FormBuilder.php line 11:
Undefined offset: 0 (View: ..\resources\views\pages\posts\password.blade.php)
I cannot understand what I am doing wrong. Please help me out.TIA.

Resources