How do I put fill out this field in Laravel? - laravel-5

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']); !!}

Related

how to fix Object of class Illuminate\Database\Eloquent\Collection could not be converted to int

when i want to create new post it is return this error Object of class Illuminate\Database\Eloquent\Collection could not be converted to int (View: C:\xampp\htdocs\new-project\resources\views\admin\posts\create.blade.php
public function create()
{
$categories = Category::all('id','name');
return view('admin.posts.create')->with('categories', $categories);
}
my view is
<div class="row">
<div class="col-md-8 col-md-offset-2 panel panel-default">
<h1>ایجاد پست</h1>
{!! Form::open(['method' => 'POST','action'=>'AdminPostsController#store','files'=>true]) !!}
<div class="form-group">
{!! Form::label('title','عنوان:') !!}
{!! Form::text('title',null,['class'=>'form-control']) !!}
</div>
{{--<div class="form-group">--}}
{!! Form::label('category_id','بخش:') !!}
{{--{!! Form::select('category_id',[''=>'زیر مجموعه مورد نظر را انتخاب کنید']+$categories,null,['class'=>'form-control']) !!}--}}
{{--</div>--}}
{!! Form::select('category_id',[''=>'زیر مجموعه مورد نظر را انتخاب کنید']+$categories,null,['class'=>'form-control']) !!}
<div class="form-group">
{!! Form::label('photo_id','عکس:') !!}
{!! Form::file('photo_id',['class'=>'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('excerpt','خلاصه:') !!}
{!! Form::text('excerpt',null,['class'=>'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('title','متن:') !!}
{!! Form::textarea('body',null,['class'=>'form-control']) !!}
</div>
<div class="form-group">
{!! Form::submit('ایجاد پست',['class'=>'btn btn-success btn-block']) !!}
</div>
{!! Form::close() !!}
#include('partcial.form-error')
</div>
</div>
<div>
<script>
$(document).ready(function() {
$('.selection').select2();
});
</script>
</div>
you can do this:
<select>
<option value=0 > زیر مجموعه مورد نظر را انتخاب کنید </option>
#foreach($categories as $category)
{
<option value={{$category->id}} > {{$category->name}} </option>
}
</select>

Missing required parameters for [Route: messenger.store]

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.

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.

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