Laravel: How to get method 'post' with link_to_action - laravel

Is there anyway i can get link_to_action in the form of method 'post'?
Here's my code
{{ link_to_action('SummaryController#viewSummaryStudent', 'View Summary', array($students->student_id),
array('class' => 'btn btn-info')) }}
Please help. Thank you!

Related

The DELETE method is not supported for this route, laravel 7, but my method isn´t DELETE

I´ve this error: The DELETE method is not supported for this route. Supported methods: GET, HEAD, POST.
But i´m not trying to delete something
My view
{!! BootForm::open(['id'=>'form', 'method' => 'POST','route'=>['declaracionenviar.enviarTodo']]); !!}
{!! BootForm::checkboxElement('ids[]', ' ', $declaracion->id, '', false, ["class"=>'check i-checks']); !!}
{!! Form::submit('Send something',['class' => 'btn btn-primary']); !!}
{!! BootForm::close() !!}
My route
Route::post('/declaracionenviar/enviarTodo','DeclaracionEnviarController#enviarTodo')->name('declaracionenviar.enviarTodo');
My controller
public function enviarTodo(Request $request)
{
$ids= $request->get('ids');
dd($ids);
}
I would appreciate some help!

Laravel Route with two parameters

I'm trying to see why i'm getting MethodNotAllowedHttpException error with put when its working fine with post method
Route::resource('record/{id}/details', 'RecordDetailController');
this works:
{{ Form::open(array('url' => '/records/' . $record->id . '/details/', 'method' => 'post')) }}
while this:
{{ Form::open(array('url' => '/records/' . $record->id . '/details/', 'method' => 'put')) }}
is getting MethodNotAllowedHttpException
thanks for the help, i found the answer from this Laravel 5 MethodNotAllowedHttpException PUT
just put
{{ method_field('PUT') }}

laravel 5.4 MethodNotAllowedHttpException in RouteCollection.php (line 251)

I'm an amateur in laravel. I use laravel 5.4. so I want to make process delete without form binding but I have an error message like this. Please tell me how to solving this.
route:
Route::delete('test/{id}','TestController#destroy');
My Form:
<td><button type="button" class="btn"><a href="{{ action('TestController#destroy', $post['id']) }}" method="post" >Hapus</button>{{ csrf_field() }}{{ method_field('DELETE') }}
</td>
My Controller:
public function destroy($id)
{
$post = Post::find($id);
$post->delete();
return redirect()->to('coba/test');`
}
Href on an anchor html element will result in a GET call but your route expect a Delete call. You have some ways to make sure you will result in a delete call.
One of the most common ways is to use a form instead to post data to your server.
Delete
{{ Form::open(['url' => 'test/'.$post->id, 'method' => 'DELETE']) }}
{{ Form::button('delete', ['type' => 'submit',
'class' => 'btn']) }}
{{ Form::close() }}
Edit
{{ Form::open(['url' => 'coba/test/'.$post->id.'/edit', 'method' => 'POST']) }}
{{ Form::button('delete', ['type' => 'submit',
'class' => 'btn']) }}
{{ Form::close() }}
For best practise I recommend to use {{ Form::open(...) }} {{ Form::close() }} only once and refactor your controller code so it can read the value from the buttons and translate that in the corresponding id of the post so you dont have multiple html forms in your code.

Laravel : I am trying to pass a variable from view to controller but it returns null

This is My View code When i am executing the application it only returns me NULL value, basically my $office_category is not being passed, i need the office category to query the database
<div class="box-body">
{{ Form::open(['route' => 'office.index','class' => 'form-horizontal office-form']) }}
<div class="form-body">
<div class="form-group">
<div class="col-md-3">
{{ Form::select('office_category', [
null=>'Please Select',
'Software' => 'Software',
'Computer Hardware' => 'Computer Hardware',
'Survey Instruments' => 'Survey Instruments',
'Office Equipments' => 'Office Equipments'
], isset($office_category) ? $office_category : '', ['class' => 'form-control input-xlarge select2me', 'placeholder' => 'Project Type', 'id' => 'office_category'] ) }}
</div>
{{ Form::hidden('office_category', $office_category) }}
{{ Form::submit('Search Equipment',['class' => 'btn green']) }}
</div>
</div>
{{ Form::close() }}
My Controller Code: I want the Office category thats it
Class OfficeController extends BaseController{
public function index(){
$office_category = Input::get('office_category');
if($office_category=='')
$offices = Office::orderBy('office_category', 'asc')
->get();
else
$offices = Office::where('office_category','=',$office_category)
->get();
$assets = ['table','datepicker'];
$users = User::where('client_id','=','')
->orderBy('name','asc')
->lists('name','username');
return View::make('office.index',[
'office_category' => $office_category,
'offices' => $offices,
'users' => $users,
'assets' => $assets
]);
}
Where am i going wrong please help.
You have a hidden field directly after your select that has the same name as the select. The value of this hidden field (empty) is what is getting sent to the server.
Delete this line:
{{ Form::hidden('office_category', $office_category) }}
Or rename this hidden field.
By default Form::open creates a POST request and your index method on Controller are expecting a GET request.
You need to add a new route on routes.php to match this POST request.
Route::post('index', 'OfficeController#index');
Or if you don't mind, you can set index to listen any kind of request:
Route::any('index', 'OfficeController#index');
In most of the case, above answer will solve your problem. If not, you can inspect your web request from browser and confirm value in $office_category variable.

laravel using twitter bootstrap and datepicker

I am trying to render a datepicker in the form created by laravel tags. So far, nothing else is showing except a regular text field.
I've used this for the datepicker. And I did the below in the form:
<p>{{ Form::text('dob', '', array('class' => 'form-control','placeholder' => 'تاريخ الميلاد', 'data-datepicker' => 'datepicker')) }}</p>
Nonetheless, I am only getting this:
What is the recommendation here? I also added the css and js to the header so all should be in place.
Thanks,
Update: calling datepicker js function in the footer.blade.php where all other calls are:
{{ HTML::script('/public/assets/js/bootstrap-typeahead.js') }}
{{ HTML::script('/public/assets/js/bootstrap-datepicker.js') }}
<script>
$('.datepicker').datepicker()
</script>
This still didn't change anything.
Use an id to initialize the datepicker
{!! Form::input('date', 'dob', date('d-m-Y'), ['class' => 'form-control', 'id' => 'dob', 'data-date-format' => "dd-mm-yyyy"]) !!}
and use this javascript
$('#dob').datepicker();

Resources