How to reference a controller from a laravel nova action? - php

I am trying to create a simple action in my laravel nova app which exports a resource to pdf..
the controllers are in
app/http/controllers
when i try to use a controller inside my actions calling new blablaController.. it throws an error like
Class 'App\Nova\Actions\blablaController' not found
so, how do i say that my controller is in app/http/controllers ??
i have referenced my action in the controller like:
use App\Nova\Actions\BlaBla;

Related

how to use another controller function without extends in our controller

how to use another controller function without extends in our controller
$this->load->library('../controllers/controllername');
already used
it is giving error =
Unable to locate the specified class: Session.php
Well you are not supposed to do that. If your controller uses repeatable logic, you should make class (Service for example), put the re-usable logic into it and call it in your controllers.
You can't use another controller function inside the controller. You can archive this in these two ways.
Create a Helper class
Create a generic model.

How to access to laravel routing resource methods?

I am using laravel to have access to my database. I have used the command php artisan make:controller CategoriesController --resource in the terminal to create a class where I can access different methods in one route.
The routing code for the class is: Route::apiResource("categories", CategoriesController::class);. With /categories I can get to the index() method (via get), where I can show my table values. But I do not know how I can use other methods. For example I have created test() with a simple return ["Result"=>"Working"].
I have tried /categories/test /categoriestest /categories%test but I can not show the result from test().
Simple routing works fine when I use specific routes for every method, but I want to make a more clear code so I would like to use the --resource to only have one route.

Call to undefined method Illuminate\Support\Facades\App::index()

I'm new to learning Laravel but I'm having trouble routing to controller, I have a controller named "App" and I have a function named index in it, it says it can't find it in "App" controller even though I set it in the route
Error
Error
Call to undefined method Illuminate\Support\Facades\App::index()
http://localhost:8000/anasayfa
App.php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class App extends Controller
{
public function index(){
return "anasayfa";
}
}
web.php
Route::get('/anasayfa', 'App#index');
What is the reason for this error?
A class with the name App already exists in Laravel, defined in namespace Illuminate\Support\Facades\App
if you want to use your class make sure to add
use App\Http\Controllers\App
in your web.php
It is recommended to use a different name. You should follow the conventions and name it AppController.
I'm solved.
I deleted the controller named "App" and created a controller named "AppController". But this caused a new error, Laravel could not find class "AppController". For this I updated web.php as follows;
use App\Http\Controllers\AppController;
Route::get('/anasayfa', [AppController::class, 'index']);

Laravel controller route

In Laravel 5.1 I was able to create following route:
Route::controller('posts', 'PostsController');
It was very handy, since I could use methods depending on request type:
public function getCreate()
{
// method for getting
}
public function postCreate()
{
// method for creating
}
In Laravel 5.5 it appears that this functionality (HTTP Controllers) has been removed(?) and replaced by HTTP Requests.
Requests are nice, but not that handy.. and it offers way more methods than I need.
Is there a possibility to keep using request-related method names for controllers in Laravel 5.5?
I think you can use Resource Route
Resource Controllers
Laravel resource routing assigns the typical "CRUD" routes to a controller with a single line of code. For example, you may wish to create a controller that handles all HTTP requests for "photos" stored by your application. Using the make:controller Artisan command, we can quickly create such a controller:
php artisan make:controller PhotoController --resource
This command will generate a controller at app/Http/Controllers/PhotoController.php. The controller will contain a method for each of the available resource operations.
Next, you may register a resourceful route to the controller:
Route::resource('photos', 'PhotoController');
This single route declaration creates multiple routes to handle a variety of actions on the resource. The generated controller will already have methods stubbed for each of these actions, including notes informing you of the HTTP verbs and URIs they handle.
Actions Handled By Resource Controller
Ref:
https://laravel.com/docs/5.5/controllers#resource-controllers
Route::controller() was eliminated after Laravel 5.3
Route::resource() is very specific to exactly, only create for you and let you access the seven methods to CRUD an object
If you want to create your own views, I believe you have to define all them with Route::get(), Route::post(), etc. in the routes/web file

Laravel HMVC routing to controller

I am trying to implement CodeIgniter style folder structure to use HMVC in Laravel. I am following this tutorial. However I am unable to route to the controller inside of the modules folder. My current Laravel folder structure is:
App
modules
model
view
controller
UsersController.php
I want to route to some function of UsersController.
you can simply use route as you do with normal controllers inside of default controller folder
Route::any('name', array('name' => 'SomeController#someMethod'));
but name of two controller shouldn't be same i.e controllers on controller folder and controller inside your module folder must have different name. For same name you can use namespace.

Categories