Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

nacha's avatar
Level 2

how to update admin email in settings in dashborad?

I have in dashboard settings and in settings general and in general there's : Default Email Address(for admin) that's mean I can change or update email address from there

so I want when I change email and click update the email change in database too so my question is: should I make registerController (create new admin and register) like register of user or not and where can I add this code to update email from admin dashborad thank you

{{ config('settings.default_email_address') }}

and I have in seeds:AdminsTableSeeder

<?php

use App\Models\Admin;
use Faker\Factory as Faker;
use Illuminate\Database\Seeder;

class AdminsTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        $faker = Faker::create();

        Admin::create([
            'name'      =>  $faker->name,
            'email'     =>  '[email protected]',
            'password'  =>  bcrypt('password'),
        ]);
    }
}
0 likes
10 replies
fylzero's avatar

@nacha Sounds like what you'd want is an Admin model (which you already have) and an AdminController. You can update the Admin email in the database from the update method of the AdminController like so...

$admin = Admin::find(12);
$admin->email = '[email protected]';
$admin->save();

Not sure your use case but I would break admins out of the User model. You could maybe look into using a permission management package like the Spatie package. Because an admin is really a user. Admin is just a user role.

https://github.com/spatie/laravel-permission

I may not fully understand your question but if you are trying to update the config in code you can do...

{{ config(['settings.default_email_address', '[email protected]']) }}
24 likes
siangboon's avatar

config usually is where people use to pre-set certain settings' value according to their environment and need, for dynamic value it's more practical to keep it in database instead of in config file...

nacha's avatar
Level 2

thank you @fylzero I will try this and I have controllers /admin/loginController.php

so I have to make AdminController yes or not

controllers /admin/loginController.php:

<?php

namespace App\Http\Controllers\Admin;

use Auth;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;

class LoginController extends Controller
{
    use AuthenticatesUsers;

    /**
     * Where to redirect admins after login.
     *
     * @var string
     */
    protected $redirectTo = '/admin';

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('guest:admin')->except('logout');
    }

    /**
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     */
    public function showLoginForm()
    {
        return view('admin.auth.login');
    }
    /**
 * @param Request $request
 * @return \Illuminate\Http\RedirectResponse
 * @throws \Illuminate\Validation\ValidationException
 */
public function login(Request $request)
{
    $this->validate($request, [
        'email'   => 'required|email',
        'password' => 'required|min:6'
    ]);
    if (Auth::guard('admin')->attempt([
        'email' => $request->email,
        'password' => $request->password
    ], $request->get('remember'))) {
        return redirect()->intended(route('admin.dashboard'));
    }
    return back()->withInput($request->only('email', 'remember'));
}
/**
 * @param Request $request
 * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
 */
public function logout(Request $request)
{
    Auth::guard('admin')->logout();
    $request->session()->invalidate();
    return redirect()->route('admin.login');
}
}

and to register user I have in auth /registerController.php

<?php

namespace App\Http\Controllers\Auth;

use App\Models\User;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
use Illuminate\Foundation\Auth\RegistersUsers;

class RegisterController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Register Controller
    |--------------------------------------------------------------------------
    |
    | This controller handles the registration of new users as well as their
    | validation and creation. By default this controller uses a trait to
    | provide this functionality without requiring any additional code.
    |
    */

    use RegistersUsers;

    /**
     * Where to redirect users after registration.
     *
     * @var string
     */
    protected $redirectTo = '/';

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('guest');
    }

    /**
     * Get a validator for an incoming registration request.
     *
     * @param  array  $data
     * @return \Illuminate\Contracts\Validation\Validator
     */
    protected function validator(array $data)
    {
        return Validator::make($data, [
            'first_name' => ['required', 'string', 'max:255'],
            'last_name' => ['required', 'string', 'max:255'],
            'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
            'password' => ['required', 'string', 'min:8', 'confirmed'],
        ]);
 
    }

    /**
     * Create a new user instance after a valid registration.
     *
     * @param  array  $data
     * @return \App\User
     */
    protected function create(array $data)
    {
        return User::create([
            'first_name' => $data['first_name'],
            'last_name' => $data['last_name'],
            'email' => $data['email'],
            'password' => Hash::make($data['password']),
            'address' => $data['address'],
            'city' => $data['city'],
            'country' => $data['country'],
        ]);
    }
}

fylzero's avatar

@nacha I really don't have enough information to help you make this call.

What exactly are you trying to accomplish? Can you narrow down your question?

You have a config value, a seeded admin, and Admin model, etc. What exactly are you trying to do/update?

24 likes
nacha's avatar
Level 2

I want to explain this

{{ config('settings.default_email_address') }}

in admin dashboard in settings general there's site name and in site logo there's site logo I can change or update site name or site logo from this and the result display in homepage of site and it works by doing this ```

and
    ```
 <h2 class="logo-text">{{ config('settings.site_name') }}</h2>

so I want to do the same for email address hope you understand me and thank you very much

nacha's avatar
Level 2

thank you @fylzero I will explain for exemple I make a site for you and I make admin email adress in seeds and I can login ok so and I will give it to you with the email address and later you want to update this email to your own email so you can update it from the admin dashboard and you can login with the new email address

hope you understand

fylzero's avatar

@nacha Look in your project folder under config\settings.php you should see entries for default_email_address and site_name . Most likely they should be referencing entries in your .env file in the root of your project. If they reference the .env just put whatever variables the reference in your .env file.

for example...

config\settings.php

'default_email_address' => env('DEFAULT_EMAIL')

.env

[email protected]
24 likes
nacha's avatar
Level 2

thank you

I don't have \settings.php in config

and I want to update it from admin dashboard

nacha's avatar
Level 2

can anyone help thank you

nacha's avatar
Level 2

how to update admin email in settings in admin dashborad with

{{ config('settings.default_email_address') }}

Please or to participate in this conversation.