Route::get('reports/{reports}/leave', ['as'=> 'reports.leave', 'uses' =>'ReportController#leave']);
#foreach($dat as $report)
<?php
$date=$_POST['date'];
$fdate=$_POST['fdate'];
?>
<td><a href="{{ URL::route('admin.reports.leave',$report->name,$fdate) }}">{!!$report->name!!}</td>
To pass three variable you can try the following example code:
Route:
Route::get('admin/{variable_1}/reports/{variable_2}/leave/{variable_3}', 'ReportController#leave');
Controller method :
public function leave($variable_1, $variable_2, $variable_3){
}
HTML (blade) link :
{!!$report->name!!}
Try below given code:
Route
Route::get('reports/{reports}/leave/{date}/{fdate}', [
'as'=> 'reportsLeave', 'uses' =>'ReportController#leave']);
Blade
#foreach($dat as $report)
<?php
$date=$_POST['date'];
$fdate=$_POST['fdate'];
?><td><a href="{{ URL::route('reportsLeave',[$reports => $report->name, 'date' => $date, 'fdate' => $fdate) }}">{!!$report->name!!}</td>
Controller
public function leave($reports, $date, $fdate){...}
Hope above suggested way will work for you. Best of Luck!
Related
I'm having an issue with route to my controller. Route does not use method which is defined in a controller.
This is my route:
Route::get('movie/{$id}', [
'as' => 'getMovie',
'uses' => 'MovieController#getMovie'
]);
That's the controller:
class MovieController extends Controller
{
public function getMovie($id)
{
$movie = Tmdb::getMoviesApi()->getMovie($id);
dd($movie);
}
}
And last thing, the anchor tag
<a href="{{ Route('getMovie', $movie['id']) }}" data-toggle="movie-overview">
When i go into that link it gives me URL:
http://localhost/public/movie/395992
and error NotFoundHttpException
What's wrong with it?
Change the route to:
Route::get('movie/{id}', ....
I am Using Laravel 5.2
Is There a Way To Get a Pagination Pretty URL in Laravel 5.2?
http://localhost:8000/backend/admin_user?page=10&page=1
And What I Would Like To Get,How generate Link Pretty Url:
http://localhost:8000/backend/admin_user/10/1
So you can try something like that:
Route::get('test/{page}', function ($page) {
return User::paginate(2, ['*'], 'page', $page);
});
You can achieve this with three simple steps.
Register the route:
Note the question mark, this makes the size and page values optional;
Route::get('backend/admin_user/{size?}/{page?}', ['uses' => 'BackendController#adminUser']);
Implement this function in your controller:
Note the default values, $size = 10, $page = 1. This makes sure that you don't get an error if you navigate to the url without the pagination.
<?php namespace App\Http\Controllers;
use App\Models\AdminUser;
use Illuminate\Pagination\LengthAwarePaginator;
class BackendController
{
public function adminUser($size = 10, $page = 1)
{
$collection = AdminUser::all();
$users = new LengthAwarePaginator($collection, $collection->count(), $size);
$users->resolveCurrentPage($page);
return view(backend.admin_user);
}
}
Use in your view like this:
<div class="container">
#foreach ($users as $user)
{{ $user->name }}
#endforeach
</div>
{{ $users->links() }}
I want to link to my route in blade. How can i do this?
<a href="roue" > go first</a>
if you define Route name you can use that in your blade :
define Route Name :
Route::get('/admin/transfer/forms-list', [
'as' => 'transfer.formsList',
'uses' => 'Website\TransferController#IndexTransferForms'
]);
now you can use that in your blade like this :
<a href="{{URL::route('transfer.formsList')}}" type="submit">
go first</a>
Of course if you use form collective you can use this :
{!! link_to_route('route.name', 'go first') !!}
There are few ways to use routes in a view.
The simplest one is using route() helper:
go first
If you're using Laravel Collective HTML & Forms, it will create full link, not only path to the route:
{!! link_to_route('route.name', 'go first') !!}
Or:
{!! HTML::linkRoute('mainpage', 'hey') !!}
Using URL facade. Wouldn't recommend, because you're getting redundant code:
go first
I am having trouble figuring out why my data is not being posted and stored in my database. I have used the resource routes for another form and it works fine, but here for some reason it won't work. Clicking submit just seems to refresh the page, no errors to work from!
So I have a form which gets the workout routines from a database, and on submission I want this to create a new Workout "session" in my database table (called "Workouts"). The form is this:
{{ Form::open(array('url' => '/')) }}
<div class="form-group">
{{ Form::text('workout_name', Input::old('workout_name'), array('class' => 'form-control', 'placeholder' => 'Session Name')) }}
</div>
<div class="form-group">
{{ Form::select('routines', $routine_names, null, array('class' => 'form-control')) }}
</div>
{{ Form::submit('Select Routine', array('class' => 'btn btn-success pull-right')) }}
{{ Form::close() }}
In my HomeController I have this:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Routine;
use App\Workout;
class HomeController extends Controller
{
public function index()
{
$routines = Routine::all();
$routine_names = Routine::lists('routine_name');
return view('workout')->with(array('routines'=>$routines, 'routine_names'=>$routine_names));
}
public function store()
{
$workout = new Workout;
$workout->workout_name = Input::get('workout_name');
$workout->save();
}
}
I have a model created for the Workout, and the route for this page is the following:
Route::resource('/', 'HomeController');
I can't figure out where I'm going wrong. The index method in my controller is working, as it is returning the correct view with the data I need. The form also looks OK I think, as I'm posting to the same page, but submitting doesn't seem to carry out the code I have in the store method of the HomeController.
Any help would be appreciated!
Thanks :)
Change your route declaration from:
Route::resource('/', 'HomeController');
To something like this:
Route::resource('/workout', 'WorkoutController');
If you are using the resources controller creator command of php artisan then all the specific routes are created for you. To see all listed routes you can type , php artisan routes. This will show you RESTFUL routes even for your POST method .
And also even you did not created the resources controller and did made the routes with manual way then you can create ,
Route::POST('/workout' , SomeController#post);
I am trying to say , you have to use the different POST method for the form submission .
Hope this will solve your problem . Thanks.
I've created my route:
Route::get('fichas/orden/{id}', 'FichaController#orden');
My Controller:
public function orden($id)
{
return $id;
}
And I have this in my View:
{{ link_to_route('fichas.orden', 'Guardar orden', array($ficha->id), array('class' => 'btn btn-primary')) }}
And I don't know why I'm having this error. I have been using this kind of routes and views all the time and I haven't got any problem until now. Does anybody know why it doesn't work now?
If you want to link to a named route, you have to define the route as follows:
Route::get('fichas/orden/{id}', array('as'=>'fichas.orden', 'uses'=>'FichaController#orden'));