Undefined offset 0 laravel blade - laravel

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.

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.

My view displays raw blade code

I'm new to Laravel and using ver 5.5. I have a simple view and when I run the code, instead of showing the rendered version, I see the Blade commands.
This is the view code:
#section('content')
<div class="row">
<div class="col-lg-12 margin-tb">
<div class="pull-left">
<h2>{{ $title }}</h2>
</div>
<div class="pull-left">
{!! \App\Combine\BaseCombine::tableHeader($collection) !!}
{!! \App\Combine\BaseCombine::tableData($collection) !!}
{!! \App\Combine\BaseCombine::tableFooter($collection) !!}
</div>
<div class="pull-right">
<a class="btn btn-primary" href="{{ route('transaction.index') }}"> Back</a>
</div>
</div>
</div>
#endsection
Here is the code in the controller that executes the view:
return view('general.genericTable',
[
'title' => __FUNCTION__,
'transactionID' => $transactionsID,
'type' => $type,
'collection' => TransactionCombine::agents($transactionsID, $type),
]
);
This is what I see when I execute the code:
#section('content')
{{ $title }}
{!! \App\Combine\BaseCombine::tableHeader($collection) !!} {!! \App\Combine\BaseCombine::tableData($collection) !!} {!! \App\Combine\BaseCombine::tableFooter($collection) !!}
Back
#endsection
What have I done wrong?

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

foreach loop in a form to save values

I try to save two values from text field but actually with this view when i click on save i get only the first ID of the foreach.
the two text field are : resultat_domicile and resultat_visiteur i would like to get the values foreach objects
someone know how to achieve this ? thanks a lot in advance
here my view :
#foreach($rencontres as $rencontre)
{!! Form::open(array('route' => array('add.resultat', $rencontre->id)))!!}
<div class="box-body">
<div class="row">
<div class="col-md-5">
<h2 class="pull-right"><div class="fa fa-shield pull-right"></div>{{$rencontre->equipe_domicile->lb_equipe}}</h2>
</div>
<div class="col-md-2">
<div class="row">
<div class="col-xs-5">
{!! Form::text('resultat_domicile', null , ['class' => 'form-control', 'placeholder' => 'Ex: 20 points']) !!}
</div>
<div class="col-xs-2 text-center">
<span class="h2">-</span>
</div>
<div class="col-xs-5">
{!! Form::text('resultat_visiteur', null , ['class' => 'form-control', 'placeholder' => 'Ex: 20 points']) !!}
</div>
</div>
</div>
<div class="col-md-5">
<h2 class="pull-left"><div class="fa fa-shield pull-left"></div>{{$rencontre->equipe_visiteur->lb_equipe}}</h2>
</div>
</div>
<div class="box-footer">
<div class="col-xs-12 text-center">
{!! Form::submit('Save', ['class' => 'btn btn-info btn-lg center-block']) !!}
{!! Form::close() !!}
</div>
</div>
#endforeach
here my controller :
public function addResultat(Request $request , $id){
$rencontre = Rencontre::findOrFail($id);
$rencontre->resultat_domicile = $request->input('resultat_domicile');
$rencontre->resultat_visiteur = $request->input('resultat_visiteur');
dd($rencontre);
}
Are you sure you're not only retrieving the LAST of the 'recontres'? When you create those form elements with the names 'resultat_domicile' and 'resultat_visiteur', you are overwriting which field gets sent to the request.
If you put a [] after the name, then they will be an array of values when they get sent to the request.
For example, this would be:
{!! Form::text('resultat_domiciles[]', ...

Resources