i'm using form collective in laravel for 2 difference form and got error. Here is my view
<div class="table-list-donor">
{!! Form::model($transactions, ['route' => ['admin.update',$transactions->id ],'file'=>true, 'id'=>'project-form','method'=>'POST']) !!}
#include('admin.patials.form',['title' => 'edit form','submit' => 'edit'])
{!! Form::close() !!}
</div>
and here is my route
<td class="action">
edit
</td>
error is Route [] not defined in route . please help!
Related
I have this code for my form and it works well:
<div class="form-group">
<select class="form-control" id="exampleSelect1">
<option>Assign</option>
#foreach ($projects as $project)
<option>{{ $project->name }} </option>
#endforeach
</select>
</div>
but what I'm trying to do is this with a contact form:
<div class="form-group">
{!! Form::label('name', 'Project') !!}
{!! Form::select (#theforeach with the values :c ) !!}}
</div>
I'm using the use App\Http\Requests\ContactFormRequest; and I have been searching the way of doing it but there is to few examples on google.
Form is part of the Laravel Collective HTML library, you can find the documentation here, specifically you're looking for the Select documentation:
echo Form::select('size', ['L' => 'Large', 'S' => 'Small']);
You have a Collection of Project models, each with a name and (presumably) an id which you need to turn into a key -> value array for the select method which you can do using pluck:
{!! Form::select('project', $projects->pluck('name', 'id')) !!}
Then within your controller you'll be able to find the project that has been selected using find, e.g:
Project::find($request->project);
If you want your select options to works, you need to call it properly,
From controller,
// Example : This is for single view page
$list_of_options = Products::pluck('name','id');
return view('your_view_name',compact('list_of_options'));
// Example : If you want select dropdown in all page ( within the controller views) then,
use Illuminate\Support\Facades\View;
public function __construct(){
View::share('list_of_options',Products::pluck('name','id'));
}
Now in blade,
{{ dd($list_of_options); }} // Check if the values are comming in proper formate
{!! Form::select('name_of_the_select', $list_of_options, null ,[
'class' => 'form-control',
'id' => 'name_of_the_select'
]);
!!}
Here is the button with <i> or <span> inside of it :-
{{ Form::button(
'<span class="fa fa-play fa-1x"></span>',
[
'class'=>'btn btn-info',
'type'=>'button'
])
}}
From your question ( UPDATED )
<div class="form-group">
{!! Form::label('exampleSelect1', 'Project') !!}
{!! Form::select('projects', $projects, null ,[
'class' => 'form-control',
'id' => 'exampleSelect1',
'placeholder' => 'Please select project'
]);
!!}
</div>
I hope this helps. :)
Try this
<div class="form-group">
{!! Form::label('project', 'Project') !!}
{!! Form::select ('project', $projects->pluck('name')) !!}}
</div>
See docs https://laravel.com/docs/4.2/html#drop-down-lists
<div class="form-group">
{!! Form::label('project', 'Project') !!}
{!! Form::select ('project', $projects->pluck('name', 'id')) !!}}
</div>
Good day to all, I am new to Laravel framework and as I read some articles about HTTP verbs which say that POST is universal to both PUT and DELETE (reference:
https://softwareengineering.stackexchange.com/questions/114156/why-are-there-are-no-put-and-delete-methods-on-html-forms
) and thus I wonder if it is possible to achieve Update and Delete functionality with POST and without using hidden() in the view itself. For example, if you look at the code below hidden method is used to clarify which HTTP verb should be used in this case PUT and what if I remove it and try to update the data will it be possible.
The code:
#extends('layouts.app')
#section('content')
<h1>Income</h1>
<br>
{!! Form::open(['action'=>['IncomeController#update',$income->id], 'method' =>'POST']) !!}
<div class="form-group">
{{Form::label('Title', 'Title')}}
{{Form::text('Title', $income->Title, ['class' =>'form-control', 'placeholder' =>'Enter title'])}}
</div>
**{{Form::hidden('_method', 'PUT')}}**
{{Form::submit('Create', ['class'=>'btn btn-primary'])}}
{!! Form::close() !!}
#stop
suppose if you have Route like this
Route::put('income/update/{id}', 'IncomeController#update');
Route::delete('income/delete/{id}', 'IncomeController#delete');
Then you can replace your route with this
Route::post('income/update/{id}', 'IncomeController#update');
Route::post('income/delete/{id}', 'IncomeController#delete');
And then change your form like this (Just remove the hidden field)
#extends('layouts.app')
#section('content')
<h1>Income</h1>
<br>
{!! Form::open(['action'=>['IncomeController#update',$income->id], 'method' =>'POST']) !!}
<div class="form-group">
{{Form::label('Title', 'Title')}}
{{Form::text('Title', $income->Title, ['class' =>'form-control', 'placeholder' =>'Enter title'])}}
</div>
{{Form::submit('Create', ['class'=>'btn btn-primary'])}}
{!! Form::close() !!}
#stop
in my view page I have this route:
{!! Form::open(['url' => 'forumcomment/' . $forum->slug, 'files'=>false, 'id' => 'qw-commentform' ,'class' => 'qt-clearfix']) !!}
<hr class="qt-spacer-s"><div class="input-field">
{!! Form::textarea('comment', null, ['class'=>'materialize-textarea', 'id'=>'my-editor', 'required'=>'required','aria-required'=>true]) !!}
<label for="comment" class="">Comment*</label></div>
<hr class="qt-spacer-s">
{!! Form::submit('Post Comment', array( 'class'=>'qt-btn qt-btn-primary qt-btn-xl' )) !!}
{!! Form::close() !!}
getting mixed content error How can I get a secure route?
add this to the boot method of your AppServiceProvider.
This loads all content over http on local development and https on production
$this->app['request']->server->set('HTTPS', $this->app->environment() != 'local');
and always change your environment to production on production.
I have only two forms for the moment in my view, they are both post method I tried to solve it like this
route
Route::post('view', function(){
if(Input::has('form1')){
'NameController#method1';
} elseif (Input::has('form2')){
'NameController#method2';
}
});
view
{!! Form::open(array('url' => '/view')) !!}
{!! Form::text('text', $trans->text) !!}
{!! Form::submit('Submit', array('name' => 'form1' )) !!}
{!! Form::close() !!}
{!! Form::open(array('url' => '/view')) !!}
{!! Form::text('text', 'text') !!}
{!! Form::submit('Submit', array('name' => 'form2')) !!}
{!! Form::close() !!}
And it throw's out this error
syntax error, unexpected ''ConfigurationController#title' (T_CONSTANT_ENCAPSED_STRING)
it was error in coding I corrected it but it won't do what I wish it simply returns blank screen it doesn't cycle trough controllers
I modified the code(removed return and closed the route)
What you want to do is create a method someMethodName in the NameController and in there
public function someMethodName()
{
if(Input::has('form1')){
$this->method1();
} elseif (Input::has('form2')){
$this->method2();
}
}
then replace all the route stuff with
Route::post('view', 'NameController#someMethodName')
This is my route
Route::resource('admin/reports', 'ReportController');
This is controller function
public function store(Request $request)
{
return "Thank you";
}
This is my html code
{!! Form::open([ 'url' => 'admin/reports/store', 'files' => true, 'enctype' => 'multipart/form-data', 'class' => 'dropzone', 'id' => 'reportfile' ]) !!}
{!! csrf_field() !!}
<div class="col-md-12">
<h3 style="text-align : center">Select File</h3>
</div>
<div class="col-md-12" style="text-align: center; padding: 10px">
<button type="submit" class="btn btn-primary">Upload Report</button>
</div>
{!! Form::close() !!}
When I submit the form, it show me MethodNotAllowedHttpException in RouteCollection.php line 218:
Any help is much appreciated. Thanks
Your form action should just be admin/reports.
Currently it will assume you are trying to post to the route admin/reports/{id}. That endpoint is used with GET, PUT and DELETE.
Check the docs including a table giving you routes https://laravel.com/docs/5.1/controllers#restful-resource-controllers if I were you I'd use the route helper to generate your urls for you