I am using laravel 5.2 and following is my code
I am getting error
ReflectionException in Route.php line 280:
Method App\Http\Controllers\Signup_controllers::guestcheckout() does not exist
whats wrong i am doing? plz help
this is my route.php
Route::group(array('prefix' => 'signup'), function()
{
Route::resource('/register', 'Signup_controllers#register');
Route::resource('/guestcheckout', 'Signup_controllers#guestcheckout');
Route::resource('/login', 'Signup_controllers#login');
Route::resource('/logout', 'Signup_controllers#logout');
Route::resource('/ajaxCheckCustomerEmailExist', 'Signup_controllers#ajaxCheckCustomerEmailExist');
});
this is my signup controller
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Input;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\HttpFoundation\Session\Session1;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\Redirect;
use Image;
use Session;
use DB;
use Mail;
use App\Http\Models\Frm_mailing_list;
use App\Http\Models\Frm_contactus;
use App\Http\Models\Emailautoresponse;
use App\Http\Models\Adminemail;
use App\Http\Models\Emailsetting;
use App\Http\Models\Product_price;
class Signup_controllers extends Controller
{
public function index(Request $request)
{
}
public function register(Request $request)
{
include(public_path().'/app/Http/Controllers/action/register_controllers.php');
}
public function login(Request $request)
{
include(public_path().'/app/Http/Controllers/action/login_controllers.php');
}
public function logout()
{
Session::flush();
return Redirect::away(url('/login-registration'))->send();
}
public function guestcheckout(Request $request)
{
include(public_path().'/app/Http/Controllers/action/guestcheckout_controllers.php');
}
public function ajaxCheckCustomerEmailExist(Request $request)
{
//Checked By Ranjit
$email=$request->email;
$customerData=array('email'=>$email);
$Customer=new Customer;
$resultCustomer=$Customer->getByAttributesQuery($customerData);
if($resultCustomer['recordCount']>0){
echo "false";
}else{
echo "true";
}
}
}
when i try to call guestcheckout it says method not found even i have defined it
Route::get('/register', 'Signup_controllers#register');
You're including controllers within Controllers and alsorts of things are wrong with your code that are going to cause you problems
I'd consider reading the documentation to understand how Laravel works
You are using Resource Controllers incorrectly. See Laravel Documention.
https://laravel.com/docs/5.4/controllers#resource-controllers
change:
Route::resource('/guestcheckout', 'Signup_controllers#guestcheckout');
to
Route::post('/guestcheckout', 'Signup_controllers#guestcheckout');
and do the same thing for other routes, replace resource with post or get for your needs
Laravel resource routing assigns the typical "CRUD" routes to a
controller with a single line of code. and you call it like this :
Route::resource('photos', 'PhotoController');
Related
**Target class ** does not exist. ?? Why I didn't understand
Error Is lluminate\Contracts\Container\BindingResolutionException
Target class [app\Http\Controllers\FrontEnd\IndexController] does not exist.
Illuminate\Container\Container::build
C:\xampp\htdocs\check-time.com\vendor\laravel\framework\src\Illuminate\Container\Container.php:875
I am Using Laravel 8. Environment information
Laravel version
8.47.0
Laravel locale
en
Laravel config cached
true
PHP version
8.0.6
<?php
namespace App\Http\Controllers\FrontEnd;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
class IndexController extends Controller
{
public function UserGuide(){
return view('FrontEnd.FrontWeb.User-Guide');
}
public function About(){
return view('FrontEnd.FrontWeb.about');
}
public function Download(){
return view('FrontEnd.FrontWeb.download');
}
public function ContectUs(){
return view('FrontEnd.FrontWeb.contact-us');
}
}
Here is My Web.php Route
<?php
use Illuminate\Support\Facades\Route;
use app\Http\Controllers\Controller;
use Illuminate\Support\Facades\Auth;
use App\Http\Controllers\Backend\AdminDashboardController;
use App\Http\Controllers\Backend\CategoryController;
use App\Http\Controllers\UserGuide\UserGuideController;
use App\Http\Controllers\Backend\AdminController;
use App\Http\Controllers\FrontEnd\IndexController;
// front end Route All GO Here
Route::get('/', function () {
return view('FrontEnd.FrontWeb.index');
});
Route::get('/User-Guide',[IndexController::class,'UserGuide'])->name('User.Guide');
Route::get('/about',[IndexController::class,'About'])->name('About.Page');
Route::get('/check-time-Software-download',[IndexController::class,'Download'])->name('Download.Page');
Route::get('/contact-us',[IndexController::class,'ContectUs'])->name('Contact.Us');
// Admin Route All Here
Route::middleware(['auth:sanctum', 'verified'])->get('/dashboard', function () {
return view('dashboard');
})->name('dashboard');
Route::get('logout/',[AdminController::class,'logout'])->name('user.logout');
Namespaces are case-sensitive. In Laravel, the app namespace is with a lowercase a.
Method 1 :
Just import your controller in the routes file, like the following example, or use full path with controller file.
use App\Http\Controllers\IndexController;
Route::post('/about' , 'IndexController#About');
//OR
Route::get('/about', 'App\Http\Controllers\IndexController#About');
Method 2 :
Go to app/Providers/RouteServiceProvider.php and find and enable this line, as it should be commented.
protected $namespace = 'App\\Http\\Controllers';
I'm having some problems with my Laravel APP.
I'm using laravel 8 and every time when I try to visit home page it gives me like:
Function () does not exist
This is how my routes looks like:
Route::get('/{any}', [VueController::class])->where('any', '.*');
And here how VueController looks like:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\User;
class VueController extends Controller
{
public function __invoke()
{
return view('application');
}
}
VueController::class second parameter is missing it should be
Route::get('/{any}', [VueController::class,'index'])->where('any', '.*');`
then in controller
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\User;
class VueController extends Controller
{
public function index()
{
return view('application');
}
}
Route::get() get req second array must have function name like [VueController::class,'index']
if you don't want to mention index then in resouncse it is possible but it generate some url with some function it will not work in __invoke()
ref link https://laravel.com/docs/8.x/routing
Routes.php
use Illuminate\Http\Request;
Route::get('/age/{val}','AgeController#store');
AgeController.php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
class AgeController extends Controller
{
//
public function store(Request $request)
{
$data = $request->input('val');
var_dump($data);
}
}
My url is localhost/lara/public/age/20.
but
output:array(0) { }
When I change $request->input('val',500);
then output: int(500)
How to get 20 (val) in controller? Why array empty?
If your controller method is also expecting input from a route parameter, simply list your route arguments after your other dependencies. Add $val as the 2nd parameter in you store function. In your case it should be
public function store (Request $request,$val){dd($val);}
I try to use SublimeLinter-phplint to lint my php files in Sublime Text 3. The linter is ran, but does not follow the 'use' statements, thus it does not understand my inheritance and raises more errors. For example, here's a controller :
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
class TestController extends Controller
{
public function __construct()
{
$this->middleware('auth');
}
public function index(Request $request)
{
return response()->json([], 200);
}
}
The first error I get is
ERROR: unknown type `Controller'
followed by
ERROR: unknown method App\Http\Controllers\TestController::middleware
Which clearly shows that phplint is not able to understand the 'use' statement. What are the steps to resolve this ? Is it a configuration issue or is phplint not able to do that ? (I'm using laravel 5)
You should remove use App\Http\Controllers\Controller; this. This might create problem. The Controller code will be
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class TestController extends Controller
{
public function __construct()
{
$this->middleware('auth');
}
public function index(Request $request)
{
return response()->json([], 200);
}
}
Laravel 5.1
This seems strange to me:
Route::group([
'middleware'=>['auth','acl:view activity dashboard'],
'prefix' => 'api/v1'
], function(){
Route::controller('investment-transactions', 'Api\V1\Investments\InvestmentTransactionsController');
Route::controller('investment-transactions/{offeringID}', 'Api\V1\Investments\InvestmentTransactionsController#getTransactionsForOffering');
});
Seems pretty normal to me, the controller:
namespace App\Http\Controllers\Api\V1\Investments;
use App\Brewster\Models\Company;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class InvestmentTransactionsController extends Controller {
public function __construct() {
}
public function getIndex() {
echo 'Here';
}
public function getTransactionsForOffering($offeringID) {
echo $offeringID;
}
}
Ok so the action and the controller do exit, but when I run: php artisan routes:list I get:
[ReflectionException]
Class App\Http\Controllers\Api\V1\Investments\InvestmentTransactionsController#getTransactionsForOffering does not exist
Well obviously App\Http\Controllers\Api\V1\Investments\InvestmentTransactionsController#getTransactionsForOffering is not a class, how ever: App\Http\Controllers\Api\V1\Investments\InvestmentTransactionsController is and getTransactionsForOffering is an action.
Whats going on?
I believe your problem is in the routes.php we can use controllers as follows
Route::get('investment-transactions', 'InvestmentTransactionsController#index');
Route::get('investment-transactions/{offeringID}', 'InvestmentTransactionsController#getTransactionsForOffering');
By default, our controllers are stored in App/http/controllers folder and laravel know it.
I believe you only need to reference the Class like so:
Route::controller('investment-transactions','InvestmentTransactionsController#Index'); //make sure you create a function for the index
Route::controller('investment-transactions/{offeringID}', 'InvestmentTransactionsController#getTransactionsForOffering');
Assuming you need to show a view for the route investment-transactions create the following function in your controller:
public function index()
{
return view('name-of-your-view-file');
}