Route in Laravel Blade show double prefix - laravel

I'm new in Laravel and now I'm trying to make link in my blade files.
I read that in many tutorials, you can just use href="{{route('mm-admin/blog')}}" to make it works.
And by works I mean the list should be like this "mm-admin/blog".
But what i get using that code is "mm-admin/mm-admin/blog".
I tried to remove the mm-admin from this code "route('mm-admin/blog')" and it returns error saying
blog isn't defined.
what is wrong with my code??
this is my blade file
<li class="{{ request()->is('mm-admin/dashboard') ? 'active' : '' }}">
<a href="{{route('dashboard')}}">
<i class="fas fa-home"></i> <span>Dashboard</span>
</a>
</li>
and this is my web route
Route::group(['prefix' => 'mm-admin', 'as' => 'mm-admin.'], function () {
Route::get('/', 'Admin\LoginController#showLoginForm')->name('login');
Route::get('/login', 'Admin\LoginController#showLoginForm')->name('login');
Route::post('/proseslogin', 'Admin\LoginController#login');
Route::get('/blog', [
'as' => 'blog',
'uses' => 'Admin\BlogController#index', 'middleware' => 'admin',
]);
});

This should work:
href="{{route('mm-admin.blog')}}"

Related

Unable to get input data from Form submit GET request in laravel 5.1 [duplicate]

This question already has answers here:
Can't retrieve url GET parameters with Laravel 5.1on remote server
(2 answers)
Closed 2 years ago.
I have a search form that is sending a GET request to the method that it is using to view the form:
<form class="form-horizontal" method="GET" action="{{ route('LoggedIn.StudentModule.StudentHomeWork.index') }}">
<div class="form-group form-group-sm">
<div class="col-sm-3">
<input type="text" name="inputdate" class="form-control datepicker" placeholder="Date" >
</div>
<div class="col-sm-2">
<button class="btn btn-primary btn-sm btn-block" type="submit">
<i class="fa fa-search" aria-hidden="true"></i>
Search
</button>
</div>
</div>
</form>
And the route:
Route::group(array(
'middleware' => 'auth',
'prefix' => '!',
'namespace' => 'LoggedIn',
'as' => 'LoggedIn.',
), function() {
.................
Route::group(array(
'prefix' => 'StudentModule',
'namespace' => 'StudentModule',
'as' => 'StudentModule.'
), function () {
............
Route::group(array(
'prefix' => 'StudentHomeWork',
'as' => 'StudentHomeWork.',
), function () {
Route::get('/', array(
'as' => 'index',
'uses' => 'StudentHomeWorkController#index'
));
});
..................
});
...............
});
And my controller:
public function index()
{
$searchParam = request('inputdate') ? request('inputdate') : date('Y-m-d');
echo $searchParam; // this is showing no data
}
The problem is, i couldn't get the data from submitted form. I have used every option that i found in stackoverflow but couldn't get the data. Can anyone point me out what i am missing! My laravel version is 5.1
Note: I am using this method in Laravel 5.8 + 6. Which is working just fine
Try This
How To Pass GET Parameters To Laravel From With GET Method ?
Route::get('any', ['as' => 'index', 'uses' => 'StudentHomeWorkController#index']);
Then Controller
public function index(){
$searchParam = Input::get('category', 'default category');
}
Form:
{{ Form::open(['route' => 'any', 'method' => 'GET'])}}
<input type="text" name="inputdate"/>
{{ Form::submit('submit') }}
{{ Form::close() }}
There Also various method...
Change it as your need.. You can also pass it in url like:
Route::get('any/{data}','StudentHomeWorkController#index')->name('something);
Controller:
public function index($data){
print_r($data);
}
Hope it will help

Laravel current route name contains

I have a group of routes like so:
Route::group(['prefix' => 'messages'], function () {
Route::post('/', ['as' => 'messages.store', 'uses' => 'MessagesController#store']);
Route::get('{id}', ['as' => 'messages.show', 'uses' => 'MessagesController#show']);
Route::put('{id}', ['as' => 'messages.update', 'uses' => 'MessagesController#update']);
Route::get('{id}/read', ['as' => 'messages.read', 'uses' => 'MessagesController#read']); // ajax + Pusher
});
In my side bar I'd like to highlight the area the user is in when they click on any of these routes:
<li class="d-flex flex-column {{ (Route::currentRouteName() == 'messages') ? 'active' : '' }}">
This would work if the route was 'messages'. is there away I can do it to be like Route::currentRouteNameContains... Obviously that's not a Laravel method but how can I have it active if it CONTAINS messages?
See str_contains helper function
<li class="d-flex flex-column {{ str_contains(Route::currentRouteName(), 'messages') ? 'active' : '' }}">
Beware that this would return true even if the route is /user/chat/messages/unread which is probably not what you want
You may look at starts_with
<li class="d-flex flex-column {{ starts_with(Route::currentRouteName(), 'messages') ? 'active' : '' }}">
Laravel 6+ users
The helper functions no longer ship with the default installation
You need to install the laravel/helpers package
composer require laravel/helpers
You can use getPrefix() helper function, too.
{{ request()->route()->getPrefix() === '/messages' ? 'active' : '' }}
Also you can use Route facades to do this. result will same with first
{{ Route::current()->getPrefix() === '/messages' ? 'active' : '' }}
Or combine basename() like below
{{ basename(request()->route()->getPrefix()) === 'messages' ? 'active' : '' }}

Issue with a tag in laravel

I have a route
Route::get('/Appraisal_cycle', [
'uses' => $namespacePrefix . 'Users#Appraisal2',
'as' => 'Appraisal_cycle'
]);
and href
<a href="{{ route('voyager.users.Appraisal_cycle') }}" class="btn btn-primary">
Appraisal Form
</a>
And my function
public function Appraisal2() {
echo 'hii';
}
but when i click this a tag it will shows page not error.Any help would be appreciated.
Here is your route
Route::get('/Appraisal_cycle', [
'uses' => $namespacePrefix . 'Users#Appraisal2',
'as' => 'Appraisal_cycle'
]);
and you can try to write this code in your controller
For APIs
public function Appraisal2()
{
return \Response::json([
'hello' => "World"
]);
}
For Web
public function Appraisal2()
{
return view("home");
}
And your home.blade.php file should be inside resources -> views directory

laravel route nott defined

route: web.php routes definitions
Route::group(['prefix' => 'admin', 'namespace' => 'Admin'], function() {
Route::get('/home', 'AdminController#home');
Route::get('/manage', 'AdminController#manage');
});
sidebar links routes is missing
<li class="nav-item">
<a href="{{route('admin.manage')}}" class="nav-link">
<i class="fa fa-circle-o nav-icon"></i>
<p>Employees</p>
</a>
</li>
Because you don't named routes. Try this code.
Route::group(['prefix' => 'admin', 'namespace' => 'Admin'], function() {
Route::get('/home', 'AdminController#home')->name('admin.home');
Route::get('/manage', 'AdminController#manage')->name('admin.manage');
});
See also documentation https://laravel.com/docs/5.6/routing#named-routes
You can also add as parameter in grouping
Route::group(['prefix' => 'admin', 'namespace' => 'Admin', 'as' => 'admin.'], function() {
Route::get('/home', 'AdminController#home')->name('home');
Route::get('/manage', 'AdminController#manage')->name('manage');
});

Laravel 4 URL::route

I've got an controller function that deletes an account. It's basically an route. I've read the manual and there is
URL::route('name of the route');
But how could I do it in the ?
like input it in here:
<td><a class="btn btn-mini btn-danger" href="the url goes here"><i class="icon-trash icon-white"></i> Delete</a></td>
You need to explicitly 'name' the route if you want to call it by a route name:
Route::post('delete_character', array(
'as' => 'delete_character', // This is the route's name
'uses' => 'AuthController#delete_character'
));
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">
discard</a>
If you are using Blade Template Engine,
Here is the solution:
<td><a class="btn btn-mini btn-danger" href="{{URL::route('controller.delete')}}"><i class="icon-trash icon-white"></i> Delete</a></td>

Resources