Problem with logout in system Aravel 5.3

Asked

Viewed 251 times

1

I have an admin who is already logging in correctly, I have the logout function done but this giving the following error: when I logout says that there is no column remember_token on my table.

How can I fix this? Because I created custom tables.

Controller

namespace App\Http\Controllers\admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\User;
use DB;
use Auth;
use Redirect;
use Hash;
use Illuminate\Support\Facades\Input;

class LoginController extends Controller
{
    public function showLogin ()
    {
        if (Auth::check()){
            return Redirect::to('/admin');
        }
        return view('admin/login');
    } 

    public function postLogin()
    {
        $username = Input::get('username');
        $passwd   = Input::get('password');

        $user = User::where('username', $username)->first();

        if ($user && Hash::check($passwd, $user->passwd)) {
            Auth::login($user);
            return Redirect::intended('admin');    
        }

        return Redirect::back()->with('error_message', 'Dados Incorrectos')->withInput();
    }

    public function logOut()
    {
        Auth::logout();
        return Redirect::to('admin/login')->with('error_message', 'Logged out correctly');
    }
}
  • Tried to create this attribute remember_token on your table?

2 answers

1

This happens because you are using a table that is not standard Laravel 5.3, follows the migration creation for the table.

If you want to create the table from scratch.

public function up()
    {
        Schema::create('NOME DA SUA TABELA', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name')->unique();
            $table->string('email')->unique();
            $table->string('password');
            $table->rememberToken();
            $table->timestamps();
        });
    }

If you want to edit the existing table.

public function up()
        {
            Schema::table('NOME DA SUA TABELA', function (Blueprint $table) {
                $table->rememberToken();
            });
        }

0


When you create your migrations add a column to that table:

...
$table->rememberToken();
...

You can also do it manually by adding the column remember_token with the default value NULL on your table:

ALTER TABLE admins ADD COLUMN remember_token VARCHAR(100) DEFAULT NULL;
  • And important this field ?

  • It is so that the "Laravel" knows that it is a table "with authentication system" @Césarsousa

  • OK understood and resolved adding this field I try an answer as the other solves the problem but I’ll take for granted yours that was the first to be given

  • 1

    @Césarsousa both are right, mine just gives a "manual" way to do this, Incredible as it seems there are many people who does not migrate like this because it already gets SQL ready

  • @Miguel as migrations facilitate both to do versioning and when developing rsrs.

  • Of course I do, I do it whenever I can, but don’t rule out the possibility that you’re migrating an entire app to Latin, then you get SQL and all the content from the @Felipepaetzold Database

  • @Good Miguel in this case is more complicated, but usually I get applications from scratch so fortunately I don’t have this problem ^^

  • @Felipepaetzold, it’s not even that complicated just by creating the BD and putting the SQL you get running, then "just" you have to make the models and their relations, you don’t need to be creating the Migrations

  • I’ve seen them use liquibase (similar to Migrations) to migrate a database mysql for oracle, rode in the liquibase the exact structure and generated the bank, was beautiful to see

Show 4 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.