dokunbam

Experience

420

0 Best Reply Awards

  • Member Since 2 Weeks Ago
  • 0 Lessons Completed
  • 0 Favorites

17th January, 2018

dokunbam left a reply on Route Not Defined For Logout • 4 days ago

Thanks

@thomaskim

Can you please explain

I was trying to do what I did here

Controller

 public function getDeletePost($post_id)
    {
     $post = Post::where('id',$post_id)->first();
     $post->delete();
     return redirect()->route('dashboard')->with(['message' => 'Successfully deleted' ]);
    }


Route

Route::get('dashboard', [
        'uses' => '[email protected]',
        'as'   => 'dashboard'
    ])->middleware('auth');

dokunbam started a new conversation Route Not Defined For Logout • 4 days ago

I want to log users out but I cant redirect back to login page

I want to use login route

Route::get('/', function () {
    return view('home');
     });

    Route::get('/login', function(){
        return view('home');
    });

    Route::get('/logout',[
        'uses' => '[email protected]',
        'as'   => 'logout'
        ]);


    Route::post('/signup', [
        'uses' => '[email protected]',
        'as'   => 'signup'
    ]);

    Route::post('/signin',
        [
        'uses' => '[email protected]',
        'as'   => 'signin'
        ]
    );

Route::get('dashboard', [
        'uses' => '[email protected]',
        'as'   => 'dashboard'
    ])->middleware('auth');

Route::post('createpost',
    [
        'uses' => '[email protected]',
        'as'   => 'createpost'
    ])->middleware('auth');

Route::get('/delete/{post_id}',
    [
       'uses' => '[email protected]',
        'as'  => 'delete'
    ])->middleware('auth');

Route::get('/logout',
    [
       'uses' => '[email protected]',
       'as'   => 'logout'
    ]);

But I keep getting route not defined

Controller

  public function logout()
    {
        Auth::logout();
        return redirect()->route('login');
    }

view
```

9th January, 2018

dokunbam left a reply on Route Protection With Middleware • 1 week ago

@tykus Thanks. its working fine now

I was just trying to do something simple.

Let say I want to protect and redirect another route like http://localhost:8000/dashboard/user-manual/user-settings (I can certainly create the route)

I want to redirect users to http://localhost:8000/dashboard/user-manual to perform a certain task before they can go to

http://localhost:8000/dashboard/user-manual/user-settings

How would I add to the existing Authentication exception in Handler.php?

public function render($request, Exception $exception)
    {
        if ($exception instanceof \Illuminate\Auth\AuthenticationException) {
            return redirect('login');
        }

        return parent::render($request, $exception);
    }

dokunbam left a reply on Route Protection With Middleware • 1 week ago

@Snapey Thanks for the observation

I am still getting

"Route [login] not defined."

after doing this

    Route::get('/', function () {
    return view('home');
     });

 
    Route::post('/signup', [
        'uses' => '[email protected]',
        'as'   => 'signup'
    ]);

    Route::post('/signin',
        [
        'uses' => '[email protected]',
        'as'   => 'signin'
        ]
    );

Route::get('dashboard', function(){
    [
        'uses' => '[email protected]',
        'as'   => 'dashboard'
    ];
})->middleware('auth'); 

I tried several things to redirect back or to 'home' route Do I need to create another home route? What am I doing wrong?

I tried this as well

    Route::get('/', function () {
    return view('home');
     });

 
    Route::post('/signup', [
        'uses' => '[email protected]',
        'as'   => 'signup'
    ]);

    Route::post('/signin',
        [
        'uses' => '[email protected]',
        'as'   => 'signin'
        ]
    );

Route::get('dashboard', function(){
    [
        'uses' => '[email protected]',
        'as'   => 'dashboard'
    ];
})->middleware('auth'); return redirect()->back();

8th January, 2018

dokunbam left a reply on Route Protection With Middleware • 1 week ago

Sorry it http://localhost:8000/dashboard

But I am getting

Route [login] not defined."

dokunbam left a reply on Route Protection With Middleware • 2 weeks ago

I don't want users to visit /dashboard directly without logging in.

I can still access the link directly by typing the link into the address bar. I will be directed to the dashboard.

When I type this localhost:8000/home/dashboard, I am directed straight to the dashboard without logging in

dokunbam left a reply on Route Protection With Middleware • 2 weeks ago

According to @burlresearch

I did this

<?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::group(['middleware' => ['web']], function(){

    Route::get('/', function () {
    return view('home');
     });

 
    Route::post('/signup', [
        'uses' => '[email protected]',
        'as'   => 'signup'
    ]);

    Route::post('/signin', [
        'uses' => '[email protected]',
        'as'   => 'signin',
    ]);
});


Route::get('/dashboard', [
    'uses' => '[email protected]',
    'as'   => 'dashboard',
])->middleware('auth');

But still not working. Pardon me I am new to laravel and PHP

7th January, 2018

dokunbam started a new conversation Route Protection With Middleware • 2 weeks ago

I want to protect dashboard so that if you don't login you cant access the dashboard route. user to be redirected if not signed in

Middleware/CheckUser.php

<?php

namespace App\Http\Middleware;

use Closure;

class CheckUsers
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next, $guard = null)
    {
        if(Auth::guard($guard)->guest())
        {
            if($request->ajax())
            {
                return response('Unauthorised.', 401);
            }else{
                return redirect()-route('home');
            }
        }
        return $next($request);
    }
}

routes/web.php

<?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::group(['middleware' => ['web']], function(){

    Route::get('/', function () {
    return view('home');
     });

 
    Route::post('/signup', [
        'uses' => '[email protected]',
        'as'   => 'signup'
    ]);

    Route::get('/dashboard', [
        'uses' => '[email protected]',
        'as'   => 'dashboard',
    ]);

    Route::post('/signin', [
        'uses' => '[email protected]',
        'as'   => 'signin',
        'middleware' => 'auth'
    ]);
});

dokunbam left a reply on Auth::attempt Not Checking If Password Is Correct, But Checking Email • 2 weeks ago

Thanks everyone Its working

dokunbam left a reply on Auth::attempt Not Checking If Password Is Correct, But Checking Email • 2 weeks ago

I always login even with the wrong password. But will not log in with the wrong email.

With wrong email and wrong password, it won't log in With correct email and wrong password, it will log in

Here is another error, I don't know if this is related. everything so far has been about the password field.

I am validating the registration fields, each time I create a user, I always get "The password field is required."

UserController.php

namespace App\Http\Controllers;

use App\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;



class UserController extends Controller
{
  public function getDashboard(){

    return view('dashboard');

  }

  public function postSignUp(Request $request)
  {
    $this->validate($request, [
            'email' => 'required|email|unique:users',
            'password' => 'required|min:4',
            'fullname' => 'required|max:120'
    ]);


    $email = $request['email'];
    $fullname = $request['fullname'];
    $password = bcrypt($request['password']);

    $user = new User();
    $user->email = $email;
    $user->fullname = $fullname;
    $user->password = $password;

    $user->save();

    return redirect()->route('dashboard');

  }

  public function postSignIn(Request $request)
  {
    if(Auth::attempt(['password' => $request['password'], 'email' => $request['email']])) 
      {
       return redirect()->route('dashboard');
      }
      return redirect()->back();

  }
}

 ?>

home.blade.php

@extends('layout/master')
@section('title')
Home!
@endsection

@section('content')
<div class="row">
   @if(count($errors) > 0)
       <div class="row">
        <div class="col-md-12">
          <ul>
            @foreach($errors->all() as $error)
            <li>{{ $error}}</li>
            @endforeach
          </ul>
        </div>
       </div>

  @endif
</div>
<div class="row" style="padding-top:10px;">
  <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
    <h3 class="text-center text-primary">Register Here</h3>
  <form method="post" action="{{URL('/signup')}}">
  <div class="form-group">
    <label for="Email">Email</label>
      <input type="email" class="form-control" name="email" id="Email" placeholder="Email">
  </div>

  <div class="form-group">
    <label for="name">Full Name</label>
      <input type="text" class="form-control" name="fullname" id="fullname" placeholder="Your Full Name">
  </div>

  <div class="form-group">
    <label for="Password">Password</label>
      <input type="password" class="form-control" id="inputPassword3" placeholder="Password">
  </div>

  <div class="form-group row">
    <div class="col-sm-10">
      <button type="submit" class="btn btn-primary">Sign up</button>
    </div>
  </div>
  <input type="hidden" name="_token" value="{{ Session::token() }}">
</form>
  </div>

  <div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
      <h3 class="text-center text-success">Login Here</h3>
  <form method="post" action="{{URL('/signin')}}">
  <div class="form-group">
    <label for="Email">Email</label>
      <input type="email" class="form-control" name="email" id="Email" placeholder="Email">
  </div>

  <div class="form-group">
    <label for="Password">Password</label>
      <input type="password" class="form-control" id="inputPassword3" placeholder="Password">
  </div>

  <div class="form-group row">
    <div class="col-sm-10">
      <button type="submit" class="btn btn-success">Sign in</button>
      <input type="hidden" name="_token" value="{{ Session::token() }}">
    </div>
  </div>
</form>
  </div>
</div>
@endsection

6th January, 2018

dokunbam started a new conversation Auth::attempt Not Checking If Password Is Correct, But Checking Email • 2 weeks ago

I want Auth::attempt() to check both password and email.

It's only checking the email. I thought it's checking only the first parameter, I have to make password the first parameter but still not checking it. Any way out of this?

Here is my UserController.php

<?php
namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

use App\User;

class UserController extends Controller
{
  public function getDashboard(){

    return view('dashboard');

  }

  public function postSignUp(Request $request)
  {
    $email = $request['email'];
    $fullname = $request['fullname'];
    $password = bcrypt($request['password']);

    $user = new User();
    $user->email = $email;
    $user->fullname = $fullname;
    $user->password = $password;

    $user->save();

    return redirect()->route('dashboard');

  }

  public function postSignIn(Request $request)
  {
    if(Auth::attempt(['password' => $request['password'], 'email' => $request['email']])) 
      {
       return redirect()->route('dashboard');
      }
      return redirect()->back();

  }
}

 ?>

dokunbam left a reply on SQLSTATE[23000]: Integrity Constraint Violation: 1048 Column 'email' Cannot Be Null (SQL: Insert Into `users` (`fullname`, `email`, `password`, `updated_at`, `c • 2 weeks ago

Thanks, everyone.

I got a new Laravel installation and the error is not showing anymore.

dokunbam left a reply on SQLSTATE[23000]: Integrity Constraint Violation: 1048 Column 'email' Cannot Be Null (SQL: Insert Into `users` (`fullname`, `email`, `password`, `updated_at`, `c • 2 weeks ago

@mathiaseverson

After adding dd($request->all());

I got this

array:5 [▼
  "_token" => "lqTkoVLWmFcItdtt8k63MDCT86rboz4llE4WNkq4"
  "fullname" => "Adedokun Bamigboye"
  "email" => null
  "password" => "1234"
  "pass" => null
]

I don't why the email is not coming through

5th January, 2018

dokunbam left a reply on SQLSTATE[23000]: Integrity Constraint Violation: 1048 Column 'email' Cannot Be Null (SQL: Insert Into `users` (`fullname`, `email`, `password`, `updated_at`, `c • 2 weeks ago

I did this but still not working

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class User extends Model
{
    //
    protected $fillable = ['fullname', 'email', 'password'];
}

dokunbam left a reply on SQLSTATE[23000]: Integrity Constraint Violation: 1048 Column 'email' Cannot Be Null (SQL: Insert Into `users` (`fullname`, `email`, `password`, `updated_at`, `c • 2 weeks ago

I am new to php and laravel though

This user model

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class User extends Model
{
    //
}

dokunbam started a new conversation SQLSTATE[23000]: Integrity Constraint Violation: 1048 Column 'email' Cannot Be Null (SQL: Insert Into `users` (`fullname`, `email`, `password`, `updated_at`, `c • 2 weeks ago

I am stuck with this error. Can someone help me out, please

View

@extends('layout/master')

@section('title')
Home!
@endsection

@section('content')
<div class="row style=padding-top: 20px;">
        <div class="col-lg-6 col-md-6 col-xs-12">
            <h3 class="text-center text-primary">Register</h3>
            <form action="{{URL('signup')}}" method="post">
              {{ csrf_field() }}

                <div class="form-group">
                    <label for="name">Your Full Name</label>
                    <input class="form-control" type="text" name="fullname" id="name">
                </div>

                <div class="form-group">
                    <label for="email">Your Email</label>
                    <input class="form-control" type="email" name="email" id="email">
                </div>

                <div class="form-group">
                    <label for="password">Password</label>
                    <input class="form-control" type="password" name="password" id="pass">
                </div>

                <!--<div class="form-group">
                    <label for="repeat-pass">Repeat Password</label>
                    <input class="form-control" type="password" name="repeat-pass" id="repeat-pass">
                </div>-->

                <div class="form-group">
                        <input class="btn btn-primary" type="submit" name="pass" id="pass">
                    </div>
                <input type="hidden" name="_token" value="{{Session::token()}}"
            </form>

        </div>
        <div class="col-lg-6 col-md-6 col-xs-12">
            <h3 class="text-center text-danger">Login</h3>
            <form action="" method="post">
                    <div class="form-group">
                        <label for="email">Your Email</label>
                        <input class="form-control" type="email" name="email" id="email">
                    </div>

                    <div class="form-group">
                        <label for="password">Password</label>
                        <input class="form-control" type="password" name="pass" id="pass">
                    </div>

                    <div class="form-group">
                            <input class="btn btn-danger" type="submit" name="pass" id="pass">
                        </div>
                </form>


            </div>
        </div>

@endsection

<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateUsersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->increments('id');
            $table->timestamps();
            $table->string('fullname');
            $table->string('email');
            $table->string('password');
            $table->rememberToken();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('users');
    }
}

UserController.php

<?php
 namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\User;
class UserController extends Controller
{
  public function postSignUp(Request $request)
  {
    $fullname = $request['fullname'];
    $email    = $request['email'];
    $password = bcrypt($request['password']);

    $user = new User;

    $user->fullname = $fullname;
    $user->email    = $email;
    $user->password = $password;

    $user->save();

    return redirect()->back();
  }
  public function postSignIn()
  {

  }
}

dokunbam left a reply on "Class App\Http\Controllers\UserController Does Not Exist" • 2 weeks ago

Thanks its working now but another error

SQLSTATE[HY000] [1045] Access denied for user 'homestead'@'localhost' (using password: YES) (SQL: insert into `users` (`fullname`, `email`, `password`, `updated 

.env

APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:XpZCGtit45zul0//15wWdpzKHa4twAz+CYcO3iVqa4w=
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://localhost

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel_social
DB_USERNAME=root
DB_PASSWORD=

BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
SESSION_LIFETIME=120
QUEUE_DRIVER=sync

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=

dokunbam left a reply on "Class App\Http\Controllers\UserController Does Not Exist" • 2 weeks ago

Thanks, everyone, the response here is awesome and super fast. I am happy I can get the quick reply here and everyone is ready to help.

I think its working now, there is a wrong file name.

But when I tried my form I got

The page has expired due to inactivity. 

Please refresh and try again.

dokunbam left a reply on "Class App\Http\Controllers\UserController Does Not Exist" • 2 weeks ago

@lostdreamer_nl This is my route

Route::group(['middleware' => ['web']], function(){

    Route::get('/', function () {
        return view('home');
    });

    Route::post('/signup', [
        'uses' => '[email protected]',
        'as'   => 'postSignUp'
        ]);
});

4th January, 2018

dokunbam left a reply on "Class App\Http\Controllers\UserController Does Not Exist" • 2 weeks ago

I have included the code

dokunbam started a new conversation "Class App\Http\Controllers\UserController Does Not Exist" • 2 weeks ago

I am a beginner to PHP and laravel I am having this error

This is user controller

Edit Your Profile
Update

Want to change your profile photo? We pull from gravatar.com.