PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, February 1, 2022

[FIXED] Connection for a user

 February 01, 2022     laravel, laravel-5     No comments   

Issue

I have for my table 'Student' 5 fields id, name, firstname, email, phone.

My question: I would like the user to connect by putting his name what should I change?

public function index(Request $request)
    {   
        $user = $request->user();
        $students= Student::query()
        ->when($user->hasRole('admin') !== true, function (Builder $query) use ($user) {
            $query->where('email', $user->email);
        })
        ->when($request->has('search'), function (Builder $query) use ($request) {
            $query->where('name', 'like', '%'.$request->input('search').'%');
        })
        ->paginate(5);



    return view('admin.students.index', compact('students'))
        ->with('display_search', $user->hasRole('admin'));
    }

Here:

$query->where('email', $user->email);

I have to put this?

  $query->where('name', $user->name);

Thank you for your help.


Solution

If you want to change the authentication credential from email to another column in the user's table, override the username function in the app/Http/Controllers/Auth/LoginController.php

/**
 * Get the login username to be used by the controller.
 *
 * @return string
 */
public function username()
{
    return 'name';
}


Answered By - Salim Djerbouh
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing