my Auth::attempt() returning fail everytime, I'm using my own subscribers table, i have already changed settings in config/auth.php to use subscribers table.
below is my logincontroller
<?php
namespace App\Http\Controllers;
use App\Http\Requests;
use App\Subscriber;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Input;
class LoginController extends Controller
{
public function login()
{
$email = Input::get('email');
$password = Input::get('password');
// $subscriber = Subscriber::where('email', $email)->first();
// $checked = Hash::check($password, $subscriber->pass);
if (Auth::attempt(['email' => $email, 'pass' => $password]))
{
return 'it workedddd.';
}
else
return 'failed';
}
}
subscriber model
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Subscriber extends Model
{
protected $fillable = [
'firstname',
'lastname',
'email',
'pass',
'phone',
'address',
'city',
'state',
'zip'
];
protected $hidden = ['password', 'remember_token'];
}
subscriber controller
<?php
namespace App\Http\Controllers;
use App\Subscriber;
use Carbon\Carbon;
use Illuminate\Http\Request;
use App\Http\Requests;
use Validator;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Input;
class SubscribersController extends Controller
{
public function newSubscriber(Request $request) //function to register new subscriber
{
$validator = Validator::make($request->all(), [
'firstname' => 'required',
'lastname' => 'required',
'email' => 'required|email|unique:subscribers,email',
'password' => 'required|min:5',
'address' => 'required',
'city' => 'required',
'state' => 'required',
'zip' => 'required',
'phone' => 'required|unique:subscribers,phone'
]);
if ($validator->fails()) {
return redirect('/register')
->withErrors($validator)
->withInput();
}
$subscriber = new Subscriber();
$subscriber->firstname = Input::get('firstname');
$subscriber->lastname = Input::get('lastname');
$subscriber->email = Input::get('email');
$subscriber->pass = Hash::make(Input::get('password'));
$subscriber->address = Input::get('address');
$subscriber->city = Input::get('city');
$subscriber->state = Input::get('state');
$subscriber->zip = Input::get('zip');
$subscriber->phone = Input::get('phone');
$subscriber->trial_time = 30;
$subscriber->date_signed_up = Carbon::now();
$subscriber->next_bill_date =Carbon::now()->addMonth(1);
$subscriber->account_status = 'trial';
$subscriber->save();
return $subscriber;
}
}
routes
Route::get('/', function () {
return view('home');
});
Route::post('/', 'LoginController@login');
Route::get('contact', function() {
return view('contact');
});
Route::get('register', function() {
return view('register');
});
Route::post('register', 'SubscribersController@newSubscriber');
Route::get('feedback', function() {
return view('feedback');
});
Route::get('dashboard', array(
'before' => 'auth.basic',
function(){
return view('dashboard.user');
}));
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire