When i try to register an account it comes up with this error " class App\Game\user" not found
I have changed the providers auth.php to App\Game\User::class,
and i have changed the name space on the user.php to namespace App\Game;
Game.php does exist (however nothing is coded in it and im wondering if this is the problem?)
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\Game\User::class,
],
the browser highlights the return line in this part of the RegisterController
protected function create(array $data)
{
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => Hash::make($data['password']),
]);
}
Edit: I didn't realize it meant folders in the naming convention and put them into the appropriate folders. Thank you. My apologies i couldn't find a question relating to this on stackover flow and ive only just started on laravel
First of all if you have something like App\Game\User::Class
That means you will have a game folder inside the app folder and then user.php file in that Game folder with. You can use the full namespace to call the class like \App\Game\User if it's still not working try to run composer dump-autoload to regenerate the composer files.
Laravel model stores under app>user.php and make sure your file does exist in app>game folder
Related
I generated my StorePostRequest using artisan make command.
I defined rules on the rules method doing this:
public function rules()
{
return [
'title' => 'required|min:3|max:255',
'slug' => ['required', Rule::unique('posts', 'slug')],
'thumbnail' =>'required|image',
'excerpt' => 'required|min:3',
'body' => 'required|min:3',
'category_id' => 'required|exists:categories,id'
];
}
However, in my PostController, I'm not able to get validated inputs except thumbnail using the safe()->except('thumbnail') like explained here
I'm getting the error
BadMethodCallException
Method App\Http\Requests\StorePostRequest::safe does not exist.
Check your laravel/framework version by running
php artisan --version
The safe method found on the FormRequest class was only added in version 8.55.0.
Just good to keep in mind that just because you're on a version 8 of laravel framework, that doesn't mean you'll have all methods and properties found in the laravel 8.x docs. That is unless you're on the current latest version 8 of course.
Using the except() method directly on $request worked. Thanks to #JEJ for his help.
$request->except('thumbnail');
We store our authentication information in a different table and column names than Laravel uses by default. It's still stored in MySQL. When doing research, in the documentation it says that we have to write completely different authentication handlers.
Is there really not any way to just remap the table and column names in a central place?
If not is there a better way to handle this? Should we just create a new table using the authentication information?
You can change your table/model name for authentication purposes inside the config\auth.php file.
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\User::class,
],
// 'users' => [
// 'driver' => 'database',
// 'table' => 'users',
// ],
],
Now, when it comes to changing column name by default Laravel using email field which you can change by putting a function username() which will return the field to be used for authentication inside LoginController.php.
public function username()
{
return 'username';
}
Hopefully this helps.
The Model associated with the login process can be modified in:
config/auth.php
under the 'providers' section:
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => \App\Models\MyOwnUsersTable::class,
],
],
However, the login process is a bit more tricky. the LoginController uses the AuthenticatesUsers trait, where you may override the required methods. For example the login method
class LoginController extends Controller
{
use AuthenticatesUsers;
public function login(Request $request)
{
//Do whatever you have to do
return $this->sendLoginResponse($request);
}
}
So, basically, I encourage you to study the
Illuminate\Foundation\Auth\AuthenticatesUsers
and reuse as much as possible from that class, and only override the methods you need to.
I tried to change User Model that used by default when use command php artisan ui:auth
to another model
but all of way to do that is not working
What should to do that ?
I am using laravel version 7.x
You can have different (or as many different) models as you want for various reasons. You just need to change the relevant section in config/auth.php. I always use a Models directory, so one of the first things I do with a new app is to relocate the User model and then tell Auth where to look for it:
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\Models\User::class,
],
// 'users' => [
// 'driver' => 'database',
// 'table' => 'users',
// ],
],
You also have to update the model's use statements in your controllers if you have custom logic, but for a vanilla Laravel Auth set-up, you should be good just by changing the config.
Edit: If you do have a structure like mine (a models directory) the default App\User namespace declaration has to change on the model itself:
Change:
namespace App;
To:
namespace App\Models;
Or whatever it is that matches your structure.
I moved my website from localhost to shared hosting all it's good, but i need when i upload file stored directly to public_html: something like this
public_html/storage/
I tried use somenthing like :
symlink('/home/abdoweb/bmcelarave/storage/app/public', '/bmce/public_html/storage')
the problem still exists.
my Controller :
public function addcategory(Request $request){
$title = $request->input('category_name');
$image = $request->file('category-image');
$name = $image->getClientOriginalName();
$image->move(storage_path().'/app/public/category',$name);
$data[] = $name;
$query= DB::table('category')->insert(
[
'title' => $title,
'image' => $name,
"created_at" => Carbon::now()
]);
if($query){
return redirect('categories');
}
}
My folder :
home/abdoweb/{bmcelaravel} <= my public folder
Core laravel :
home/{bmce} <= core laravel
Thank you.
You can a use storage driver :
Inside config/filesystems.php :
'disks' => [
'public' => [
'driver' => 'local',
'root' => public_path() . '/uploads',
'url' => env('APP_URL').'/public',
'visibility' => 'public',
]
]
//Now you can move the file to storage like :
Storage::disk('public')->putFile('category', $request->file('category-image'));
First of all the recommended location for that stuff is to stay on the public path not creating a new one, unless there is an actual reason for that. Did you actually check that the symlink was created?
Laravel has an own command the create a symlink from storage/app/public to public/storage (the storage folder will be generated afterwards):
php artisan storage:link
But if you want to create defaults symlinks you should create one for yourself, like you already did.
This is the symlink pattern:
ln -s target source (fill in your target and source path)
So if you actually get the correct file from your request, this code should work:
Storage::putFile($name, $request->file('category-image'));
For more and detailed infos look into the filesystem documentation
I need to add a new field named username when registering or adding a new user, so i mess with permissionmanager folder inside vendor since i have no idea how to extend it from outside the vendor folder.
[
'name' => 'username',
'label' => trans('backpack::permissionmanager.username'),
'type' => 'text',
],
thats' what i got:
I also put the language conversion in resources\views\vendor\backpack\permissionmanager\src\resources\lang\es with no success.
In the latest version of PermissionManager you can overwrite the routes. This way, you can point to your own PermissionCrudController, which would extend the PermissionCrudController from the package. Inside your PermissionCrudController you can do anything you want - including adding a new field. Your setup method could look something like this:
public function setup()
{
parent::setup();
$this->crud->addField([
'name' => 'username',
'label' => trans('backpack::permissionmanager.username'),
'type' => 'text',
])->after('name');
}
Check out the documentation for this here.
The language file should NOT be in the views folder. In should be in the LANG folder: resources\lang\vendor\backpack\es\permissionmanager.php.