laravelcollective/html not finding any of my controllers - laravel

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

Related

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.

Form model binding not working in laravel 5.2 using laravelcollective

Hello I'm new to laravel 5.2 and going through some lessons.
For some reason form model binding is not working for me.
{!! Form::model($post, ['method'=>'PATCH', 'action'=> ['PostController#update', $post->id]]) !!}
I received data in $post because I'm using a workaround like this:
{!! Form::text('title', "$post->title" ,['class'=> 'form-control']) !!}
And that is showing my data.
Controller:
namespace App\Http\Controllers;
use App\Post;
use Illuminate\Http\Request;
use App\Http\Requests;
class PostController extends Controller{
public function update(Request $request, $id){
$post =Post::findOrfail($id);
$post->update($request->all());
return redirect('/posts');
}
}
create.blade.php view:
#section('content')
<h1>Create Post</h1>
{!! Form::open(['method'=>'POST', 'action'=>'PostController#store']) !!}
<!-- Title Form Input -->
<div class="form-group">
{!! Form::label('title', 'Title:') !!}
{!! Form::text('title', 'null', ['class'=> 'form-control']) !!}
</div>
<!-- Form Input -->
<div class="form-group">
{!! Form::submit('Create Post', ['class'=> 'btn-primary form-control']) !!}
</div>
{!! Form::close() !!}
#endsection
You shouldn't be quoting the value for null in your input:
{!! Form::text('title', 'null', ['class'=> 'form-control']) !!}
should be
{!! Form::text('title', null, ['class'=> 'form-control']) !!}
Ok, try adding the body of the form into a partial called posts/partials/form.blade.phpand include it between the form open / model and form close tags.
Example:
posts/partials/form.blade.php
<!-- Title Form Input -->
<div class="form-group">
{!! Form::label('title', 'Title:') !!}
{!! Form::text('title', 'null', ['class'=> 'form-control']) !!}
</div>
<!-- Form Input -->
<div class="form-group">
{!! Form::submit($formButtonText, ['class'=> 'btn-primary form-control']) !!}
</div>
posts/create.blade.php
{!! Form::open(['method'=>'POST', 'action'=>'PostController#store']) !!}
#include('posts.partials.form', [
'formSubmitButtonText' => 'Create Post'
])
{!! Form::close() !!}
posts/edit.blade.php
{!! Form::model($post, ['method'=>'PATCH', 'action'=> ['PostController#update', $post->id]]) !!}
#include('posts.partials.form', [
'formSubmitButtonText' => 'Update Post'
])
{!! Form::close() !!}

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>

Resources