Change the routes for models in laravel 8 php artisan auth - php

I am making application with tutorial. At the very beginning, I ran the command php artisan ui:auth which created a login and registration page for me. Initially my models (eg Users) were in the App/Models/Users folder but I had to change their location to /App/Users because only then application it worked according to the tutorial. The login page itself works, but when I click the 'login' button I get an error:
Error
Class '\App\Models\User' not found
Illuminate\Auth\EloquentUserProvider::createModel
C:\xampp\htdocs\testowa4\vendor\laravel\framework\src\Illuminate\Auth\EloquentUserProvider.php:186
186 line is in the function:
public function createModel()
{
$class = '\\'.ltrim($this->model, '\\');
return new $class; //186 line
}
How to change model paths for these files? I need them outside the Models folder. Is there any way to refresh the routes or something like that?

Related

laravel making its own route to blade file

working a project with Laravel 5.6.
the problem is, when im going to an url like:
/login
or any other route and specify where it should go, it making its own route and going to another place. no metter if i even clear the code of that blade file.
i have not several routes or blade file that are the same. i have cleared my browser cache, laravel cach, config cache, and the command:
php artisan route:cache
did not worked to clear route cache.
my code example: web.php code
Route::get("/login", "LoginController#login");
Example: LoginController.php code
public function login()
{
return view('/login'); // not going to this path
}
to conclude, it does not read my code :(
need your ideas!
public function login()
{
return view('login');
}
view accepts the view name not the path of the route, If you want go to any route use redirect("/route_name") . But in your case if you redirect to login route again it will throw exception because the login route again calls this function. so you need to pass the view name. for example:
if your login view is in
resources
- views
-login.blade.php
then use above code. or if the login page is in any other folder inside view
it will be like return view("foldername.login")

Codeigniter controller method 404 error

I cloned a copy of Codeigniter from github today using this link: https://github.com/bcit-ci/CodeIgniter.git. I am currently running MAMP setup so that http://localhost:8888 points to my htdocs folder. My root folder is called 'time'. When I go to http://localhost:8888/time/index.php, I do see the Codeigniter welcome page. Also, I can go tohttp://localhost:8888/time/ and see the same welcome page, even though I don't have an .htaccess file in the root directory.
Here is the problem. I added the following function to the Welcome.php controller class:
public function test()
{
echo 'Test';
}
This should display a page which shows 'test' when I visit http://localhost:8888/time/index.php/test. However, I get a 404 page not found error. Does anyone have any suggestions for understanding and fixing this problem?
Because localhost/index.php/test doesn't refer to the method test in the welcome controller. You would have to go to localhost/index.php/welcome/test or use routes.
They way you are doing it implies there is a controller named Test.php and it is trying to go to the index() function of that controller.

How to integrate other pages into laravel pre-built authentication

After reading some tutorials on laravel 5.4 authentication (including the doc),I don't know how to work with it in my file.
I have been able to run the artisan command.. php artisan make:auth. Have seen the the controller, views etc that was created and even have accessed it by going to http://localhost/blogsite/public/register (don't worry about, its on my local disk) but how do I integrate it with with the pages that needs authentication? That I don't know..
Who can put me through how to integrate it with other pages
Many way you can use for this solution.
First Way:
If you load views file from controller just use the following line to your controller.
Suppose my controller name is DashBoardController
public function __construct()
{
$this->middleware('auth');
}
So all of the view you return from DashboardController it will make you auth for you. That means if you return any of view from this controller you must need to log in.
So you need to put this constructor function to all of your Controller from where you return view and need to authenticate the user.
To avoid this constructor funtion to all controller you can use the following
Way using route:
Route::group(['middleware' => 'auth'], function () {
Route::Your_Request_Method('your_url1', 'YourController1');
Route::Your_Request_Method('your_url2', 'YourController2');
});
You can get more way at laravel authentication documentation
Hope you will understand.

Delete session in laravel5.2 when cms pages accessed

I am new in laravel framework. Can anyone tell me how to delete sessions when cms pages accessed i.e(faq,privacy policy,about us). This query runs fine for me:-
$request->session()->forget('key');
The problem is that when i accessed the faq page i have write this query and when i accessed the privacy policy then again i have to write this query. Can anyone tell me how i do in one function. So i have not implement this query again and again
Thanks in advance :)
Create One middleware named as forgetSession(you can have any name) and set the cms pages route group in app\Http\routes.php under that middleware for eg.
Route::group(['middleware' => ['forgetSession']], function () {
Route::resource('faq', 'faqController');
Route::resource('privacy', 'privacyController');//likewise
});
Now create middleware by writing below command on cmd project root
php artisan make:middleware forgetSession
So it will create the middleware in app/Http/middleware/forrgetSession
and put your code
$request->session()->forget('key');
So in this way all route mentioned under route group will have the code to forget session. This way definitely you can redundant the code.
you can remove session at your controller
call this in controller contruct method
$request->session()->forget('key'); //remove by key
$request->session()->flush(); // remove all

Laravel unable to load view

Just started learning laravel I tried to create a route for my view but when I load on the web browser it says Sorry, the page you are looking for could not be found. Can any one help me out in codeigniter it was so simple just create a controller and view and we can see on the web broswer I found laravel to be difficult then codigniter is that true?? can anyone define me how is the mvc structure for laravel5 as i found tutorials but they are of old laravel and files and structure are almost change so I got confused any suggestions please
routes.php
Route::get('main', 'Main#index');
Main.php
namespace App\Http\Controller;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
class main extends Contoller {
public function _construct() {
$this->middleware('guest');
}
public function index() {
return "Hello World from controller";
}
}
if you are running laravel project locally, it can run through its own server. you dont need apache server form wamp or xampp,,but you will need their mysql database. So start only that if you require database.
Now go to command prompt, navigate to the directory where your project is stored eg cd c:/wamp/www/yourprojet and then type following command
php artisan serve
it will start on port 8000 by default. and you can now access your project at 'http://localhost:8000/'
and you can access your view at 'http://localhost:8000/main'
Also you can find laravel tutorials and other at laracast
Try to change the class name to Main (now is main, in lowecase)
I learnt Laravel by their awesome tutorial: https://laravel.com/docs/4.2/quick
make a view in resources->views, something like my-view.blade.php
Then return view('my-view');
That my-view.blade.php can have whatever HTML you want in it
Go to your resources/views folder create file with filename.blade.php.
Now in your routes.php:
Route::get('main', 'Main#index');
And in your controller add this function:
public function index() {
return view('filename');
}

Categories