Action App\Http\Controllers\AdminController#dbTanger not defined.
And this is My AdminController
public function dbTanger() {
$data = Db::table('ressos')
->where('secteur','Services')
->get();
return view('backend.layouts.admin.typeFilterTanger',compact('data','pagi'));
}
And this is the view
<div class="Filter">
<p>Filter Using Ville</p>
Tanger-Asilah
</div>
so if anyone can help me please
and thank you all
Since Laravel 9, the default Controller namespace has not been included in the RouteServiceProvider so you need to be explicit about where to locate controllers (or add the default namespace to your RouteServiceProvider).
What you can do is the following:
{{ action('\App\Http\Controllers\AdminController#dbTanger') }}
However, I would recommend using the route helper in conjunction with named routes as this is easier to manage should files change or move location in the future.
Route::get('/admin/dbTanger', [AdminController::class, 'dbTanger'])->name('admin.dbTanger');
Then use it as follows:
{{ route('admin.dbTanger') }}
The outcome is the same, just easier to manage and maintain long-term.
That error would mean you didn't define a route to this action so there is nothing in the route collection to be found for that action.
Define a route for this action and you would be able to use that action helper to create a URL to a route that uses this action.
Related
I'm trying to do my first attachment/ detachment. I'm using two tables, user, event, and its pivot, event_user. For this one, I needed to do a button to subscribe the user to an event, so my teacher told me to use an and route it to the method subscribe. At this moment, the error that comes up is.
Route [subscribe] not defined.
Blade
<a href="{{ route('subscribe', $event->event_id) }}"
class="btn btn-primary btn-lg">Subscribe</a>
Route
Route::get('/subscribe', [SubscribeController::class, 'index']);
SubscribeController
public function index($id)
{
$user = Auth::user();
$user->events->attach($id);
return view('index');
}
I tried putting URL instead of the route in the , and it goes to /subscribe, but comes to an error that says -> Too few arguments to function 0 passed and exactly 1 expected.
I did a dd() in the component to see if the event id was the correct one, and it was. Also, apart from these errors, how can I route a method without changing the route? Can I do it using the indexController (because it's in the index where these events are located)?
First, in order to reference the route by name, you need to give it the name subscribe.
Docs: https://laravel.com/docs/master/routing#named-routes
Second, you want to add that id route parameter that you are trying to use in your controller.
Docs: https://laravel.com/docs/master/routing#required-parameters
So your route should end up looking like this:
Route::get('/subscribe/{id}', [SubscribeController::class, 'index'])
->name('subscribe');
And then you'll want to call it like this:
<a href="{{ route('subscribe', ['id' => $event->event_id]) }}"
Firstly in your blade view file you are trying to generate url using route helper like this
<a href="{{ route('subscribe', $event->event_id) }}"
class="btn btn-primary btn-lg">Subscribe</a>`
The way you call the route helper we can supposed this
You have already define a route in your web.php file which is named subscribe
and that route have paramater
But in your web.php file you have this route
Route::get('/subscribe', [SubscribeController::class, 'index']);
This route doesn't have any name.
And it doesn't expect any parameter
To fix that you should only change the way you have define you route in the web.php file like this
Route::get('/subscribe/{id}', [SubscribeController::class, 'index'])
->name('subscribe');
With this route we define:
id as a required parameter
And the route is named subscribe
This is probably something simple, but it's doing my head in.
So, my layout blade template has this:
#include('layouts.partials.sidebar')
{{ $slot }}
#include('layouts.partials.footer')
#include('layouts.partials.scripts')
I create a view which loads a template. This I assume gets parsed in $slot.
return view('request', [
'boo' => 'Hoo'
]);
No problems, the page loads and the variable 'boo' is accessible as {{ $boo }} in the 'requests' template.
But my question is, how can I pass the 'boo' variable to an included file in the layout file? In this case the following:
#include('layouts.partials.scripts')
So, in 'layouts.partials.scripts' how can I access {{ $boo }}? At the moment I just get an undefined index error.
Thank you very much for the help.
#include('layouts.partials.scripts', ['boo' => 'Hoo'])
Laravel Docs
https://laravel.com/docs/8.x/blade#including-subviews
If you have a partial like a nav, header, or sidebar, part of the master layout from which you are composing other views. It requires data that doesn't change from one view to another, like navigation links. Then, instead of passing the data from each controller method, you can define a view composer in a service provider's boot() method:
Service Provider's boot method
public function boot()
{
View::composer('layouts.partials.sidebar', function ($view) {
//$links = get the data for links
return $view->with('links', $links);
});
}
Laravel Docs
https://laravel.com/docs/master/views#view-composers
I am trying to set active classes on active menus. In the past I was using Request::is() function for this, but in the new version of laravel it says "Class 'Request' not found."
As you are using blade you can use request helper method. Try like this
request()->is('your_url');
do not put / before the route.
it should be like
#if(Request::is('index'))
#include('include.showcase')
#endif
please check in your code
you add this line as namespace or not
use Illuminate\Http\Request;
and you can also pass one varriable with view from controller side and check on blade template if you get that data then you can use active class for that menu. like this
in controller what i had used in my project
$data['page-tab'] = 'adduser';
return view('user.add_user',compact('data'));
and in blade file i had checked this like this in sidebar section
<li class="{{ isset($data['page-tab']) && $data['page-tab'] == 'adduser' ? 'active' : '' }}"><i class="fa fa-file-text-o"></i>Manage Member</li>
hope this works for you.
Use it without the '/'
like this:
#Request::is('home')
not
#request::is('/home')
I am using laravel 5.5. I have created a helper.php in app\Http. I am calling this helper in my blade file by using
{!! Helper::functionName() !!}
this is working fine. but i want to hold this helper result in a variable like
{!! $Result=Helper::functionName() !!}
But currently this is printing this result. How to solve this. please help.
So that i can make any if condition on this $Result.
In my helpers.php
namespace App\Http\Helpers;
class Helper
{
public static function functionName()
{
return "mydata";
}
}
There is no point to use helper like this. You should run the helper in controller and pass calculated data into view. In most cases you shouldn't set any variables in views or make any calculations - those should be passed from controller to view and view should only use them.
In this case, you can use "<?php ?>".
So result:
<?php $Result=Helper::functionName(); ?>
may be this is not possible because in laravel "{{}}" this means echo "" so by default it will print the value. return the value from helper function and use in your blade
I am opening a form inside one of the pages generated by JeffreyWay's laravel generator.
Except it keeps saying unknown action even though i added the action in the WorkorderController. If I change it to the default actions that was created it worked fine.. like action => 'WorkordersController#create'
Does anyone know how to register a new action using the Route::Resource?
Thanks!
in my form
{{ Form::open(array('action' => 'WorkordersController#time')) }}
in my WorkorderController
public function time()
{
return 'hello world';
}
in my routes
Route::resource('workorders', 'WorkordersController');
The fastest way to resolve this is creating a separate route to your action:
Route::resource('workorders', 'WorkordersController');
Route::post('workorders/time', array('as'=>'workorders.time', 'uses'=>'WorkordersController#time'));
But you also can extend the whole Laravel router system and add new actions.