All routes throw NotFoundHttpException but home - php

I got this code in the routes.php:
Route::get('/', array('as' => 'home', function()
{
return View::make('list.open');
}));
Route::get('room/{name}', array('as' => 'showRoom', 'uses' => 'RoomController#showRoom'));
Route::post('room', array('as' => 'openRoom', 'uses' => 'RoomController#openRoom'));
And this code in the RoomController.php:
class RoomController extends Controller {
public function openRoom()
{
return "test";
}
public function showRoom($name)
{
return "test2";
}
}
If I open public/ it will Show me the view list.open but if I open public/room/test it throw the NotFoundHttpException. (I also tried to use directly a function in the routes.php instead of the roomcontroller but it doesnt worked)
Can anyone help me?
Kind regards
Damon

You don't need to add the public folder to your path, you can just go to http://location.com/room/test.

I just reinstalled a new larapack and deleted the old one... I've to start from Zero but now it works.

Related

127.0.0.1 redirected you too many times

I'm confused and looking for someone to point me in the right direction;
The route I'm trying to get to is /admin/login
I have the following AdminController file;
class AdminController extends Controller
{
// Login
function login(){
return view('backend.login');
}
function submit_login(Request $request){
$request->validate([
'username' => 'required',
'password' => 'required'
]);
$userCheck=Admin::where(['username'=>$request->username,'password'=>$request->password])->count();
if($userCheck>0){
return redirect('admin/dashboard');
}else{
return redirect('admin/login')->with('error','Invalid username/password!!');
}
}
function dashboard(){
return 'Dashboard';
}
}
and this is my web routes file;
Route::get('/', [HomeController::class,'home']);
Route::get('/admin/login', [AdminController::class,'login']);
Route::get('/admin/login', [AdminController::class,'submit_login']);
Route::get('/admin/dashboard', [AdminController::class,'Dashboard']);
Can anyone identify why the too many redirects are happening?
I'm getting a simple in chrome
This page isn’t working
127.0.0.1 redirected you too many times.
Try clearing your cookies.
ERR_TOO_MANY_REDIRECTS
TIA
EDIT: I was being silly, should've done post not get for the second route.

Laravel routing without appending any prefix

I have a path in Laravel it is like subdomain.mydomain.com/admin/login
I am trying to call
subdomain.mydomain.com and need to get the login page straight.
Currently, it's not working
This is the function I am using in routerserviceprovider.php
protected function mapAdminRoutes()
{
Route::middleware('subdomain.mydomain.com')
->prefix('admin')
->namespace($this->namespace)
->group(base_path('routes/admin.php'));
}
and in admin.php there is a resource group shows like this:
Route::group(['prefix' => 'admin', 'namespace' => 'Admin'], function() {
//Login Routes...
Route::view('login','admin.login');
});
can anyone help with this?
Add following route
Route::get('/',function(){ return view('login.index'); })->name('admin.login');
i hope it helps

How to Give Link In Menu to go menu page (laravel 4.2)

Hello Friend Thank For viewing My Question!!
I am Unable to make my menu link active
my view file code
<div class="sign-up-right">
Sign Up
</div>
My Controller File(MyCon.php)
public function singup(){
return View::make('preview',['preview'=>'signup.php']);
}
My Routes file code
Route::get('/', 'MyCon#index');
route::get('admin', array('user'=>'Admin#index'));
Route::get('/login',function(){ return View::make('preview',['preview'=>'login.php']);});
Route::get('singup', ['as' => 'signup', 'uses' => 'MyCon#signup']);
But when I am click on Signup link It Show Error Like
Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException
return new Response('', 200, array('Allow' => implode(',', $others)));
}))->bind($request);
}
$this->methodNotAllowed($others);
}
protected function methodNotAllowed(array $others)
{
throw new MethodNotAllowedHttpException($others);
}
protected function check(array $routes, $request, $includingMethod = true)
please help to make my link successful
Thank
Try to give the name to your route may solve your problem
Route::post('singup', function(){ return View::make('preview',['preview'=>'signup.php']);});
Since you're using a simple a href link, you need to change the route to Route::get:
Route::get('singup', ['as' => 'signup', 'uses' => 'MyCon#signup']);
Also, fix the link:
Sign Up

Controller changes does not reflect

I have a problem. I tried to change the controller but when I open the route it doesn't reflect with the latest controller? Any idea?
Controller
public function indexApplication(){
return "testing";
}
Api.php
Route::group(['prefix' => '/claim'], function(){
Route::get('/test', ['as' => 'claim.test', 'uses' => 'ClaimController#indexApplication']);
}
Response from rest client

Laravel auth check for all pages

I have created the Authentication, and its working perfectly. But there is some problem in checking the inner pages. For example,
Route::get('/', array('before' => 'auth' , 'do'=> function(){
return View::make('home.index');
}));
The index page is only visible for logged in users. But whenever I have go to the inner pages, for example example.com/products. The products page can be visible without log in.
Here is my solution.
/**
* Groups of routes that needs authentication to access.
*/
Route::group(array('before' => 'auth'), function()
{
Route::get('user/logout', array(
'uses' => 'UserController#doLogout',
));
Route::get('/', function() {
return Redirect::to('dashboard');
});
Route::get('dashboard', array(
'uses' => 'DashboardController#showIndex',
));
// More Routes
});
// Here Routes that don't need Auth.
There are several ways of applying filters for many routes.
Putting rotues into Route::group() or if you using controllers add the filter there, add it in the Base_Controller so it will be applied to all. You can also use filter patterns and use a regex which applies the filter to all except a few you don't want to.
Documentation
Route filters: http://laravel.com/docs/routing#route-filters
Example to the pattern filter, as the others are basicly in the docs. This one could be the fastest but also the most problematic because of the problematic way of registering a regex in this function (the * is actually converted into (.*)).
Route::filter('pattern: ^(?!login)*', 'auth');
This will apply auth to any route except example.com/login.
Route::group(['middleware' => ['auth']], function()
{
Route::get('list', 'EventsController#index');
});
Read more on the documentation page:
https://laravel.com/docs/5.2/routing#route-groups
There may be a better way but I take a whitelist approach. Everything is blocked from public except for what the pages I put in this array.
// config/application.php
return array(
'safe' => array(
'/',
'card/form_confirm',
'record/form_create',
'card/form_viewer',
'user/login',
'user/quick_login',
'user/register',
'info/how_it_works',
'info/pricing',
'info/faq',
'info/our_story',
'invite/accept',
'user/terms',
'user/privacy',
'email/send_email_queue',
'user/manual_login',
'checkin/',
'checkin/activate',
'system/list',
),
// routes.php
Route::filter('before', function()
{
// Maintenance mode
if(0) return Response::error( '503' );
/*
Secures parts of the application
from public viewing.
*/
$location = URI::segment(1) . '/' . URI::segment(2);
if(Auth::guest() && !in_array( $location, Config::get('application.safe')))
return Redirect::to( 'user/login' );
});
this code working fine with me
Auth::routes();
Route::group(['middleware' => 'auth'], function () {
// Authentication Routes...
Route::get('/', 'HomeController#index')->name('home');
});
The same problem can be solved using a BaseController to extends all Controller have must logged user.
Example:
class SomeController extends BaseController
{
public function index() { return view('some.index');}
}
just add a __construct() method to BaseController
class BaseController extends Controller
{
protected $redirectTo = '/myIndex'; // Redirect after successfull login
public function __construct()
{
$this->middleware('auth'); // force all controllers extending this to pass auth
}
}
More info here
Just check if user is logged in in your views.
Or restrict all controller (if you use it)
Or check Route Groups, and give a filter to whole group of routes: http://laravel.com/docs/routing#groups
Route::filter('pattern: /*', array('name' => 'auth', function()
{
return View::make('home.index');
}));
It worked for me . take a look at it.
Route::when('*', 'auth.basic');
Route::get('api/getactorinfo/{actorname}', array('uses' =>'ActorController#getActorInfo'));
Route::get('api/getmovieinfo/{moviename}', array('uses' =>'MovieController#getMovieInfo'));
Route::put('api/addactor/{actorname}', array('uses' =>'ActorController#putActor'));
Route::put('api/addmovie/{moviename}/{movieyear}', array('uses' =>'MovieController#putMovie'));
Route::delete('api/deleteactor/{id}', array('uses' =>'ActorController#deleteActor'));
Route::delete('api/deletemovie/{id}', array('uses' =>'MovieController#deleteMovie'));

Categories