Yield a form on a different page using laravel - 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

Related

How can I keep selected the previous value when updating a form?

I am using laravel collctive form. I want to update only the quantity field of the following form keeping the blood_id field readonly. When I submit the form I am not getting blood_id value.
How can i solve it?
{!! Form::model($bloodBank, ['route' => ['bloodBanks.update', $bloodBank->id], 'method' => 'put']) !!}
<div class="row">
<div class="col-lg-8">
<div class="form-group">
{!! Form::label('blood_id', 'Blood Group', ['class' => 'form-control-label']);!!}
{!! Form::select('blood_id', $bloods , null , ['placeholder' => 'Choose Blood Group',"class"=>"form-control",'disabled' => true]) !!}
</div>
</div>
</div>
<div class="row">
<div class="col-lg-8">
<div class="form-group">
{!! Form::label('quantity','Quantity', ['class' => 'form-control-label']);!!}
{!! Form::number("quantity",null, ["class"=>"form-control form-control-label",'min'=>'0']) !!}
<span class="validation-error">{{ $errors->first("quantity") }}</span>
</div>
</div><!-- col-12 -->
</div>
<button class="btn btn-info">Update </button>
{!! Form::close() !!}
For disabled fields, you may want to add hidden fields which won't display on the rendered page BUT will be included in the request object. E.g.
{{ Form::hidden('blood_id', $bloods) }}
This is in addition to the displayed field you already have which is disabled.

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.

laravelcollective/html not finding any of my controllers

I am getting this error from a login page
Action App\Http\Controllers\Admin\LoginController#authenticate not defined. (View: /Applications/XAMPP/xamppfiles/htdocs/lectureme/resources/views/admin/login.blade.php)
I know for certain that this controller exists though, so why is it unable to find it? I have also created a new controller in the controller root and named it TestController, and tried routing to that instead, but that was also apparently not found.
Any suggestions for how to get access to the controller? Form code:
{!! Form::open(['action' => 'LoginController#authenticate']) !!}
<div class="form-group">
<div class="form-group">
{!! Form::label('username', 'Username:') !!}
{!! Form::text('username', null, ['class'=>'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('email', 'Email Address:') !!}
{!! Form::text('email', null, ['class'=>'form-control']) !!}
</div>
</div>
<div class="form-group">
{!! Form::submit('Login', ['class'=>'btn btn-primary']) !!}
</div>
{!! Form::close() !!}
I have also tried composer dump-autoload and php artisan cache:clear
Make sure you namespaced your controller properly. Assuming you have placed your controller in the App\Http\Controllers\Admin directory it would be:
namespace App\Http\Controllers\Admin

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>

Resources