How to achieve this route? - laravel-5

I'm trying to achieve the route " /stock/{{stock->id}}/quantity ".
So i have created a folder named "quantity" inside resources/views/stocks/ .
And i have also created an index.blade.php file inside quantity.
" /stock/{{stock->id}} "shows the details of the stock i.e "show.blade.php"
Inside "show.blade.php" i have placed the link to my quantity page. Given Below is the code.
Quantity
But its not working. Am i doing correct?
I did add Route::resource('quantity', 'QuanityController'); to web.php Please help someone!
This is my controller.
namespace App\Http\Controllers;
use App\Quanity;
use App\Stock;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Auth;
class QuanityController extends Controller
{
public function index()
{
return view('quanity.index');
}
}

You should user route name in web.php don't use $ sign in parameter route use like this.
it is good to give different name to every route for its unique identification.
Route::get('/stocks/{stock_id}/quantity','QuanityController #index')->name('stock.quantity');
In blade use route name and pass parameter like this:-
Quantity
In Controller Recieve that parameter:-
class QuanityController extends Controller
{
public function index($stock_id)
{
return view('quanity.index');
}
}

Related

Laravel, Route not defined. yet it is

I'm developing an eccomerce site. and im getting this error on checkout. please help
here are the defined routes:
//payfast payment
Route::get('payment', 'PaymentController#confirmpayment')->name('confirmPayment');
Route::get('/payfast/success','PaymentController#success')->name('payment.success');
Route::get('/payfast/cancel','PaymentController#cancel')->name('payment.cancel');
and here is the Controller (destination route):
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use NunoMaduro\Collision\Provider;
use App\Models\Cart;
use App\Models\Product;
use DB;
use Billow\Contracts\PaymentProcessor;
Class PaymentController extends Controller
{
public function confirmpayment(PaymentProcessor $payfast)
{
$cart = Cart::where('user_id',auth()->user()->id)->where('order_id',null)->get()->toArray();
$data = [];
When you use Laravel Named Route name(), you have to use it.
Route::get('payment', 'PaymentController#confirmpayment')->name('confirmPayment');
Instead of using
payment
replace it with
confirmPayment
change your HTTP method from get to post
like this:
Route::post('payment', 'PaymentController#confirmpayment')->name('confirmPayment')
it seems you don't have route named payment you only have
confirmPayment
payment.success
payment.cancel

Laravel 8 subfolder Controller

I created folder in Controller. But Laravel is giving
Target class [App\Http\Controllers\SAIDE\SaideMerchantController] does not exist.
error
-->Controller
<?php
namespace App\Http\Controllers\SAIDE;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Schema;
class SaideMerchantController extends Controller
{
public function home()
{
return view('backoffice.saide.maindashboard');
}
Route::get('/maindashboard','SAIDE\SaideMerchantController#home');
}
-->end controller
How to use controller in Folder ?
We don't see a complete route file, but try the change the get method to
Rouge::get('/mainboard', [App\Http\Controllers\SAID\SaidMerchantController::class, 'home']);
Check out Laravel documentation for version 8 routing
https://laravel.com/docs/8.x/routing#basic-routing

Laravel Controller not found

I'm learning laravel and I've tried to create a Controller.
I'm really new, so, please, elaborate.
I've used the following command to create the Controller
php artisan make:controller Api/EstadoController
So, EstadoController is under Controllers/Api
I also created a route at api.php
Route::namespace('API')->name('api.')->group(function() {
Route::get('/estados', 'EstadoController#index')->name('estados');
});
EstadoController has index function and correct namespace:
<?php
namespace App\Http\Controllers\Api;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
class EstadoController extends Controller
{
public function index(){
return Estado::all();
}
}
Here is the error page:
Changing
API
to
Api
in my route resolved, like route creation.
Route:
Route::namespace('Api')->name('api.')->group(function() {
Route::get('/estados', 'EstadoController#index')->name('estados');
});
Please try to make route like this:
Route::get('/estados', 'Api\EstadoController#index');

Laravel : Class controller does not exist

I have created a simple controller and define a function. But when i run this it returns an error that controller does not exist.
In my web.php assign a route.
<?php
Route::get('/', function () { return view('front.welcome'); });
Route::get('plan','PlanController#PlanActivity')->name('plan');
On otherside in my controller my code:
<?php
namespace App\Http\Controllers\Front;
use App\Http\Controllers\Controller as BaseController;
use Illuminate\Http\Request;
class PlanController extends Controller {
public function PlanActivity()
{
dd("hello");
//return view('admin.index');
}
}
This controller created on App\Http\Controllers\Front - on front folder
Error :
ReflectionException (-1)
Class App\Http\Controllers\PlanController does not exist
Add Front part to:
Route::get('plan', 'Front\PlanController#PlanActivity')->name('plan');
Also, change the top of the controller to:
namespace App\Http\Controllers\Front;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
And run composer du.
From the docs:
By default, the RouteServiceProvider includes your route files within a namespace group, allowing you to register controller routes without specifying the full App\Http\Controllers namespace prefix. So, you only need to specify the portion of the namespace that comes after the base App\Http\Controllers namespace.
First when defining route, make sure to use the correct path for the controller. the correct is:
Route::get('plan','Front/PlanController#PlanActivity')->name('plan');
Second you have imported Controller Class as BaseController. so you should extends BaseController not Controller:
class PlanController extends BaseController {
public function PlanActivity()
{
dd("hello");
//return view('admin.index');
}
}

Routing in Laravel is not working

I am using laravel 5.0
I am trying to route the following. But it is not working
Route::post('accesscontrols/permissions', 'AccescontrolsController#permission');
I don't know what error in this.
It does not access permissions function in AccesscontrolsController
I have a function in AccesscontrolsController
public function permission()
{
$roles = DB::table('roles')->get();
$permissions = DB::table('permissions')->get();
return view('accesscontrols.permission', compact('roles', 'permissions'));
}
What I have did wrong?
Your route declaration should be made in app/Http/routes.php.
Also, make sure that your controller is within the App\Http\Controllers namespace and that it extends App\Http\Controllers\Controller.
Ex:
<?php
namespace App\Http\Controllers;
use App\User;
use App\Http\Controllers\Controller;
class UserController extends Controller
{
public function permission()
{
...
Also, if you whish to test it in the browser (by typing "accesscontrols/permissions" in the address bar), you route should answer to the GET verb. Try to declare it using Route::get( instead.
You are returning a view in your method and you are not working with any POST data, which is strange. Are you sure you want POST request and not GET?

Resources