I have my laravel project created inside laragon/www folder and I'm using dingo/api package for routing.
Here are my files
routes/web.php
<?php
Route::get('/', function () {
return view('welcome');
});
routes/api.php
<?php
use Dingo\Api\Routing\Router;
$api->get('test', 'TestController#index');
app/Http/Controllers/Api/TestController.php
<?php
namespace App\Http\Controllers\Api;
class TestController extends BaseController {
public function index() {
return 'test';
}
}
When I run artisan api/routes it gives me the URI api/test but when I try to reach it in my browser under http://localhost/myproject/public/api/test it returns error "Sorry, the page you are looking for could not be found" knowing that http://localhost/myproject/public/ returns the good result
try
<?php
$api = app('Dingo\Api\Routing\Router');
$api->get('test', 'TestController#index');
Related
i am new to laravel and i am trying to submit form into data base but i am getting error i dont know why
i have added the screen shot along with that controller
when i do dd($REQUEST->all()) i am getting the form data
<?php
namespace App\Http\Controllers;
use App\Inventory;
use Illuminate\Http\Request;
class InventoryController extends Controller
{
public function index(){
return view('invetory.index');
}
public function sales(){
return view('invetory.sale');
}
public function create(Request $REQUEST){
// dd($REQUEST->all());
inventories::Create($REQUEST->all());
}
}
web.php
<?php
use Illuminate\Support\Facades\Route;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('/inventory', 'App\Http\Controllers\InventoryController#index')->name('map');
Route::get('/inventory/sales', 'App\Http\Controllers\InventoryController#sales');
Route::get('/', function () {
return view('welcome');
});
Auth::routes();
Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home');
Auth::routes();
Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home');
Route::post('/inventory', 'App\Http\Controllers\InventoryController#create')->name('invetory.create');
according to your code the controller should look like
<?php
namespace App\Http\Controllers;
use App\Models\Inventory;
use Illuminate\Http\Request;
class InventoryController extends Controller
{
public function index(){
return view('invetory.index');
}
public function sales(){
return view('invetory.sale');
}
public function create(Request $request){
Inventory::Create($request->all());
}
}
change the namesapce of inventory to use App\Models\Inventory;
and also , inside create function use :
Inventory::Create($request->all());
I was trying to make a group routing with a prefix in Laravel 8. But when I tested it in http://localhost/mysite/admin/test/, it always throws error 404.
Here is the code in web.php:
Route::prefix('/admin', function() {
Route::get('/test', [Admin\LoginController::class, 'index']);
});
I created a controller in app/Http/Controller/Admin/ as the controller is inside Admin folder.
Here is the code in LoginController:
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class LoginController extends Controller
{
public function __construct()
{
//
}
public function index()
{
echo "Please login";
}
}
Can anybody show me what I am doing wrong to get it working?
You have to group the routes as stated in the documentation like:
Route::prefix('admin')->group(function () {
Route::get('/test', function () {
// Matches The "/admin/users" URL
});
});
In your case it would be:
use App\Http\Controllers\Admin\LoginController;
Route::prefix('admin')->group(function () {
Route::get('/test', [LoginController::class, 'index']);
});
I think it should be 'admin' not '/admin'.
That slash makes it:
http://localhost/mysite//admin/test
=>
http://localhost/admin/test
You can check all your routes using: php artisan route:list
Try this
use App\Http\Controllers\Admin\LoginController;
Route::prefix('admin')->group(function () {
Route::get('test', ['LoginController::class, index'])->name('test'); });
Can Someone please help me on laravel postcontroller? I am using Laravel 8 but I am seeing below error though my Postcontroller is existing on app>Http>Controllers>PostController.php. Below is my code and I appreciate yoenter image description hereur help in advance.
Routes
<?php
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\PostsController;
Route::get('/', function () {
return view('welcome');
});
Auth::routes();
Route:: get('/p/create','PostsController#create');
Route::get('/profiles/{users}',[App\Http\Controllers\HomeController::class, 'index'])->name('home');
PostController
use Illuminate\Http\Request;
class PostsController extends Controller {
public function create() {
return view ('posts/create');
}
}
Insead of :
Route:: get('/p/create','PostsController#create');
use :
Route:: get('/p/create',[PostsController::class , 'create']);
You can read more about laravel 8 routes here:
https://laravel.com/docs/8.x/routing#the-default-route-files
I have a problem when using /admin on the url, if I use it always gives a 404 response but, when I change /admin on web.php in other words like adnnin etc. there was no problem
here piece web.php
Route::middleware('isadmin')->group(function () {
Route::prefix('admin')->group(function () {
Route::get('/dashboard', [App\Http\Controllers\Admin\DashboardController::class, 'index']);
});
});
here my controller
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class DashboardController extends Controller
{
public function index () {
return view('pages.admin.dashboard');
}
}
Make sure you do not have a folder named admin in your public directory. The webserver will look for folder/files before falling back to handing the request off to the front loader public/index.php, the Laravel application.
I began to study Laravel, I have this problem.
File: project/app/Http/routes.php
<?php
Route::get('about', 'PagesController#about');
In the directory project I do by terminal
php artisan make:controller PagesController
File: project/app/Http/Controllers/PagesController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
class PagesController extends Controller
{
public function about()
{
return("About");
}
}
You need to enter in apache configuration file and specify AllowOverride Yes on the directory where laravel still working
You are accessing your / route in your provided image. Which is not defined in your routes.php file that's why you are getting this error.
Add
Route::get('/', function() {
return "hello world";
});
and then try this route: 192.168.1.101/laravel-p/public/
Note you've explained the about route in your above code. So hit this route
`192.168.1.101/laravel-p/public/about`
You are accessing your / route in your provided image. Which is not
defined in your routes.php file that's why you are getting this error.
Add
Route::get('/', function() {
return "hello world"; });
and then try this route: 192.168.1.101/laravel-p/public/
Note you've explained the about route in your above code. So hit this
route
192.168.1.101/laravel-p/public/about
Nothing..
enter image description here
<?php
Route::get('/', function() {
return "hello world";
});
Route::get('about', 'PagesController#about');