Laravel version - 4.2 logout is not working - php

NotFoundHttpException showing when load the page when i am logout it is showing 404 error it is showing object not found showing the rout section is given below:
route.php
Route::get('logout',array('uses' => 'LoginController#logout'));
the controller is LoginController
public function logout()
{
//Session::flush();
Auth::logout();
return Redirect::to('login');
}
and anchor tag is
<li><i class="fa fa-sign-out"></i> Logout</li>
but it is showing
Object not found! 404 error

Route::group(['namespace' => 'YourNameSpace', 'before' => 'auth'], function() {
Route::get('logout', [
'uses' => 'LoginController#logout',
]);
});
'auth' must be defined in filters

Related

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

How can i direct link into page in laravel 5.4

AdminLTE Laravel template screenshoot:
how can i direct the link into my page in folder lapor/one.blade.php and lapor/two.blade.php?
<li class="treeview">
<a><i class='fa fa-file'></i> <span>Laporan</span> <i class="fa fa-angle-left pull-right"></i></a>
<ul class="treeview-menu">
<li>One</li>
<li>Two</li>
</ul>
</li>
Make a route like below
Route::get('one', function () {
return view('lapor.one');
});
Route::get('two', function () {
return view('lapor.two');
});
And link it like below
<li>One</li>
I would group your adminLTE routes:
Route::group(['prefix' => 'admin', 'as' => 'admin.'], function()
{
Route::get('/', ['as' => 'dashboard', 'uses' => 'AdminController#index']);
Route::get('users', ['as' => 'user', 'uses' => 'AdminController#users']);
});
We prefixed those routes with /admin/ or whatever you want to call it. Then we prefixed their name with admin (using 'as').
Now get a specific route url:
{{ route('admin.dashboard') }}
Why do it like this?
Naming your routes is very important because if the route url changes and your app has hardcored urls (like url('/admin/dashboard') your entire application will break. With named routes this wont happen.
You can do it in three step:
make a function in your controller.like below
publice function functionName(){
return view('yourpagename(one)');
}
go to routes folder open web.php and connect with your controller function in routes. like
Route::get('page-name', 'controllerName#functionName');
add this url to your view page link tag
{{URL::to('page-name')}}
Hope it will works fine.
Before going to redirect the page two steps you need to do :
Step 1:
Define Methods in controller(named as SampleController) for example:
//Controller Name:SampleController
// Method Names defined in controller :lapor1,lapor2
//Method 1
public function lapor1(){
return view('lapor.one');
}
//Method 2
public function lapor2(){
return view('lapor.two');
}
Step :2
Define Routes for the pages like below:
Route::get('lapor1', ['as' => 'laporone','uses'=>'SampleController#lapor1']);
Route::get('lapor2', ['as' => 'laportwo','uses'=>'SampleController#lapor2']);
Step 3:
Link up to view pages now:
<li>One</li>
<li>Two</li>

Error Messages - Laravel 5.2

Can someone please tell me how to make my "Page not found" or something messages? For example if someone writes a link in the browser which do not exist in my project, not to show the standard error page ( Woops, something went wrong, View [bla.bla] not found ) but page specified by me?
<?php
Route::get('sendemail', 'EmailController#sendEmail');
Route::get('test', 'AuthController#getTest');
Route::get('napravisiadmin', 'ClassbookController#getIndex');
Route::group(['middleware' => ['web']], function () {
Route::group(['middleware' => ['guest']
], function () {
Route::get('login', 'AuthController#getLogin');
Route::post('login', 'AuthController#postLogin');
});
Route::get('logout', 'AuthController#getLogout');
//Admin
Route::group(['middleware' => ['auth', 'auth.admin']
], function () {
Route::group([
'prefix' => 'admin',
'namespace' => 'Admin'
], function () {
Route::controller('student', 'StudentsController');
Route::controller('profile', 'ProfilesController');
Route::controller('class', 'ClassesController');
Route::controller('subjects', 'SubjectsController');
Route::controller('teacher', 'TeachersController');
Route::controller('marktype', 'MarkTypeController');
Route::controller('rules', 'RuleController');
Route::get('{slug?}', 'PageController#getView');
});
});
//Admin
//Student
Route::group([
'middleware' => ['auth', 'auth.student'],
'prefix' => 'stu',
'namespace' => 'Stu'
], function () {
Route::get('{slug?}', 'StuController#getView');
});
//Student
//Teacher
Route::group([
'middleware' => ['auth', 'auth.teacher'],
'prefix' => 'educator',
'namespace' => 'Educator'
], function () {
Route::get('edit/{id}', 'AccountController#getEdit');
Route::post('edit/{id}', 'AccountController#saveEdit');
Route::get('account', 'AccountController#getView');
Route::get('class-subject', 'AccountController#getClassSubject');
Route::get('add-mark', 'AccountController#getAddMark');
Route::post('mark', 'AccountController#postAddMark');
Route::get('added', 'AccountController#marksList');
Route::get('statistics', 'AccountController#marksInTable');
Route::get('personalemails', 'PersonalEmailController#getView');
Route::post('personalemails', 'PersonalEmailController#personalEmail');
});
//Teacher
});
Route::get('{slug?}', 'PageController#getView');
For the "Page not found" 404 error create a view in resources/views/errors/404.blade.php and it will show when you get a 404 error.
From the documentation:
Custom HTTP Error Pages
Laravel makes it easy to return custom error pages for various HTTP
status codes. For example, if you wish to customize the error page for
404 HTTP status codes, create a resources/views/errors/404.blade.php.
This file will be served on all 404 errors generated by your
application.
The views within this directory should be named to match the HTTP
status code they correspond to.
https://laravel.com/docs/5.2/errors#custom-http-error-pages
You can always go a step further by utilising the exception handler and handling exceptions the way you desire by customising the render() method
https://laravel.com/docs/5.2/errors#the-exception-handler
For example, if you wanted to handle file not found error, Exceptions\Handler.php
public function render($request, Exception $e)
{
if ($e instanceof \Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException) {
return response()->view('errors/exceptions/file-not-found', [], 500);
}
return parent::render($request, $e);
}
You can create custom error 404 page. If someone will enter wrong URL in a browser, he will see that page.
Also, you can redirect user manually to this page with:
abort(404);
Update
I guess the problem is here:
Route::get('{slug?}', 'PageController#getView');
You're using this three times, try to remove all of them.
The thing is when Laravel doesn't find any routes, it takes {slug} and passes it to the PageController, so when you enter http://example.com/sometext, you will be transferred to the PageController with slug = sometext.
If you do not want to remove it, check for slug inside a controller and if slug means something - good. If not, just abort(404); and user will be transferred to an error page.
Also, if you're on 5.2.27 of higher, remove web middleware from routes.php (it applies automatically, and manual apply can cause errors and strage behavior).

Laravel 5.2 authentication

I've been trying to get the new release (5.2) of Laravel to work with a simple web app. However, I'm having a problem with authentication.
All pages of the app include a navigation view partial which uses Auth::user()->name to display the username in the nav if they are logged in.
In order to do this, I created a pages controller which loads the auth middleware in the constructor:
public function __construct()
{
$this->middleware('auth');
}
This works perfectly if the user is logged in. However, if the user is not logged in, they are requested to login on every page. Even pages like "contact" or "about" which clearly should not require authentication to view.
How can I make pages like "about" always accessible while still being able to access Auth in the nav?
EDIT:
Routes
Route::group(['middleware' => ['web']], function () {
Route::get('/home', 'StaticController#home');
Route::get('/about', 'StaticController#about');
Route::get('/contact', 'StaticController#contact');
});
Route::group(['middleware' => 'web'], function () {
Route::auth();
Route::get('/', 'HomeController#index');
});
StaticController
class StaticController extends Controller
{
public function home()
{
return view('static.home');
}
public function about()
{
return view('static.about');
}
public function contact()
{
return view('static.contact');
}
}
Navigation
<ul class="nav navbar-nav">
#if (Auth::guest())
<li>Login</li>
<li>Register</li>
#else
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
{{ Auth::user()->name }} <span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li><i class="fa fa-btn fa-sign-out"></i>Logout</li>
</ul>
</li>
#endif
</ul>
After deleting everything and installing a fresh copy of Laravel the problem disappeared.
You have two possible solutions:
Route middleware (can get a bit hard to maintain) https://laravel.com/docs/master/middleware#assigning-middleware-to-routes
Within your view partial you could simply have a conditional statement to check or create a method on the Auth facade. This would mean you wouldn't need the conditional. Conditional solution below:
Auth::check() ? Auth::user()->name : ''
In /app/Http/Kernel.php
check to see if you have
'auth' => \App\Http\Middleware\Authenticate::class,
Example
protected $routeMiddleware = [
'auth' => \App\Http\Middleware\Authenticate::class,
....
];
Now, you may need to re-architect your route to something like this
in your routes.php
**//Routes (Not Require Log-in)**
Route::get('/home', 'StaticController#home');
Route::get('/about', 'StaticController#about');
Route::get('/contact', 'StaticController#contact');
**//Authentication Routes**
Route::group(['middleware' => ['auth']], function () {
Route::get('/', 'HomeController#index');
//................................
// More Auth Routes Go in HERE
//................................
});
Hope it helps !
you can do something like this
$this->middleware('auth', ['only' => 'update'])
the only will be set on the specified method for example

Laravel 4 Resource routing error

I have this route :
// work
Route::resource('work', 'WorkController');
Route::get('work/{id}/delete', array('as' => 'admin.work.delete', 'uses' => 'WorkController#confirmDestroy'))
->where('id', '[0-9]+');
and my controller WorkController is residing at App/Controllers/Admin
in the view I call it like this:
<span class="glyphicon glyphicon-book"></span> <br/>Work
and I get this error:
Error Message: Class App\Controllers\Admin\Work does not exist
What is wrong with my code? I have used the same approach for pages, users and menus and it worked.
Can you confirm what is the name of controller file in App\Controllers\Admin?. Also your route should be
// work
Route::group(array('prefix' => 'admin', function()
{
Route::resource('work', 'WorkController');
Route::get('work/{id}/delete', array('as' => 'admin.work.delete', 'uses' => 'WorkController#confirmDestroy'))
->where('id', '[0-9]+');
});

Categories