dokunbam

dokunbam

Member Since 1 Year Ago

Experience Points 970
Experience
Level
Lessons Completed 0
Lessons
Completed
Best Reply Awards 0
Best Answer
Awards
  • Start Your Engines Achievement

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • First Thousand Achievement

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • One Year Member Achievement

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • Two Year Member Achievement

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • Three Year Member Achievement

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • Four Year Member Achievement

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • Five Year Member Achievement

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • School In Session Achievement

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • Welcome To The Community Achievement

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • Full Time Learner Achievement

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • Pay It Forward Achievement

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • Subscriber Achievement

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • Laracasts Evangelist Achievement

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • Chatty Cathy Achievement

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • Laracasts Veteran Achievement

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • Ten Thousand Strong Achievement

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • Laracasts Master Achievement

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • Laracasts Tutor Achievement

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • Laracasts Sensei Achievement

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • Top 50 Achievement

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

14 Nov
2 months ago

dokunbam started a new conversation Spatie Newsletter: Argument 1 Passed To Spatie\Newsletter\Newsletter::isSubscribed() Must Be Of The Type String, Null Given, Called In

I am working with Spatie Mailchimp Newsletter package. I got this error

Symfony \ Component \ Debug \ Exception \ FatalThrowableError (E_RECOVERABLE_ERROR)
Argument 1 passed to Spatie\Newsletter\Newsletter::isSubscribed() must be of the type string, null given, called in C:\Users\dokunbam\Documents\transcribe\transcript\vendor\laravel\framework\src\Illuminate\Support\Facades\Facade.php on line 223 ```

This is my newsletterController.php
05 Nov
2 months ago

dokunbam left a reply on Class App\Http\Middleware\CheckRole Does Not Exist

Thanks everyone, I appreciate everyone's effort.

I applied what @arthvrian suggested

I was about starting over again

The error has been fixed and working fine now

dokunbam left a reply on Class App\Http\Middleware\CheckRole Does Not Exist

This is my composer.json

Also User.php is in app root folder

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "type": "project",
    "require": {
        "php": "^7.1.3",
        "fideloper/proxy": "^4.0",
        "laravel/framework": "5.7.*",
        "laravel/tinker": "^1.0"
    },
    "require-dev": {
        "beyondcode/laravel-dump-server": "^1.0",
        "filp/whoops": "^2.0",
        "fzaninotto/faker": "^1.4",
        "mockery/mockery": "^1.0",
        "nunomaduro/collision": "^2.0",
        "phpunit/phpunit": "^7.0"
    },
    "autoload": {
        "classmap": [
            "database/seeds",
            "database/factories"
        ],
        "psr-4": {
            "App\": "app/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\": "tests/"
        }
    },

    "extra": {
        "laravel": {
            "dont-discover": [
            ]
        }
    },
    "scripts": {
        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate"
        ],
        "post-autoload-dump": [
            "Illuminate\Foundation\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover"
        ]
    },
    "config": {
        "preferred-install": "dist",
        "sort-packages": true,
        "optimize-autoloader": true
    },
    
    "minimum-stability": "dev",
    "prefer-stable": true
    
}

dokunbam left a reply on Class App\Http\Middleware\CheckRole Does Not Exist

@arthvrian As suggested. Already done

Role.php

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Role extends Model
{
    //
    public function roles()
    {
        return $this
            ->belongsToMany('App\User')
            ->withTimestamps();
    }
}

User.php

<?php

namespace App;

use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use Notifiable;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name', 'email', 'password',
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];

    public function users()
    {
        return $this
            ->belongsToMany('App\Role')
            ->withTimestamps();
    }

    public function authorizeRoles($roles)
    {
        if ($this->hasAnyRole($roles)) {
            return true;
    }
    abort(401, 'This action is unauthorized.');
    }
     
    public function hasAnyRole($roles)
    {
        if (is_array($roles)) {
            foreach ($roles as $role) {
                if ($this->hasRole($role)) {
                    return true;
                }
            }
    } else {
        if ($this->hasRole($roles)) {
            return true;
          }
        }
        return false;
    }
    public function hasRole($role)
    {
        if ($this->roles()->where(‘name’, $role)->first()) {
            return true;
        }
        return false;
    }

}

dokunbam left a reply on Class App\Http\Middleware\CheckRole Does Not Exist

@D9705996 This is User.php and I have checked files that I have worked with.

<?php

namespace App;

use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use Notifiable;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name', 'email', 'password',
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];

    public function users()
    {
        return $this
            ->belongsToMany('App\Role')
            ->withTimestamps();
    }

    public function authorizeRoles($roles)
    {
        if ($this->hasAnyRole($roles)) {
            return true;
    }
    abort(401, 'This action is unauthorized.');
    }
     
    public function hasAnyRole($roles)
    {
        if (is_array($roles)) {
            foreach ($roles as $role) {
                if ($this->hasRole($role)) {
                    return true;
                }
            }
    } else {
        if ($this->hasRole($roles)) {
            return true;
          }
        }
        return false;
    }
    public function hasRole($role)
    {
        if ($this->roles()->where(‘name’, $role)->first()) {
            return true;
        }
        return false;
    }

}

dokunbam left a reply on Class App\Http\Middleware\CheckRole Does Not Exist

@munazzil I am using it as adviced

namespace App\Http\Middleware;

use Closure;

class CheckRole
{

dokunbam left a reply on Class App\Http\Middleware\CheckRole Does Not Exist

composer dump-autoload done but still the same

dokunbam left a reply on Class App\Http\Middleware\CheckRole Does Not Exist

Thanks, guys I have reversed back with php artisan app:name App

This new namespace is creating a lot of confusion and might cause more problem later.

After that I tried to access /admin again I got

Call to undefined method App\User::roles()

dokunbam left a reply on Class App\Http\Middleware\CheckRole Does Not Exist

@D9705996

This is my http/User.php

<?php

namespace Transcribe;

use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use Notifiable;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name', 'email', 'password',
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];

    public function users()
    {
        return $this
            ->belongsToMany('App\Role')
            ->withTimestamps();
    }

    public function authorizeRoles($roles)
    {
        if ($this->hasAnyRole($roles)) {
            return true;
    }
    abort(401, 'This action is unauthorized.');
    }
     
    public function hasAnyRole($roles)
    {
        if (is_array($roles)) {
            foreach ($roles as $role) {
                if ($this->hasRole($role)) {
                    return true;
                }
            }
    } else {
        if ($this->hasRole($roles)) {
            return true;
          }
        }
        return false;
    }
    public function hasRole($role)
    {
        if ($this->roles()->where(‘name’, $role)->first()) {
            return true;
        }
        return false;
    }

}

This is Role.php

<?php

namespace Transcribe;

use Illuminate\Database\Eloquent\Model;

class Role extends Model
{
    //
    public function roles()
    {
        return $this
            ->belongsToMany('App\User')
            ->withTimestamps();
    }
}

dokunbam left a reply on Class App\Http\Middleware\CheckRole Does Not Exist

@Snapey

This is my middleware/checkRole.php

<?php

namespace Transcribe\Http\Middleware;

use Closure;

class CheckRole
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next, $role)
    {
        if (! $request->user()->hasRole($role)) {
            abort(401, 'This action is unauthorized.');
        }
        return $next($request);
    }
}

dokunbam started a new conversation Class App\Http\Middleware\CheckRole Does Not Exist

I followed a tutorial for admin and superadmin role and permission which I followed

But when I signed in I got this error

Call to undefined method Transcribe\User::roles()

When I navigate to /home. no error

But when I navigate to /admin or /superadmin

I got an error again

Class App\Http\Middleware\CheckRole does not exist

dokunbam left a reply on Trait 'App\Http\Controllers\Auth\AuthenticatesUsers' Not Found'

@edoc This is what is missing

use Illuminate\Foundation\Auth\AuthenticatesUsers;

but I got another error This is the initial error I was trying to fix

Call to undefined method Transcribe\User::roles()

04 Nov
2 months ago

dokunbam started a new conversation Trait 'App\Http\Controllers\Auth\AuthenticatesUsers' Not Found'

Symfony\Component\Debug\Exception\FatalErrorException …\app\Http\Controllers\Auth\LoginController.php

I made some changes to the loginController, I cant seem to get what I did wrong again

`

11 Jul
6 months ago

dokunbam left a reply on Use Vuejs On Existing Laravel App

@andreasbakir Thanks, I will try that

10 Jul
6 months ago

dokunbam started a new conversation Use Vuejs On Existing Laravel App

I want to use vuejs on a laravel application have already run auth command and some other packages.

What is the best way to use vue now. Do I start a fresh? If there is a way, how do I go about it?

07 Feb
11 months ago

dokunbam left a reply on How To Upload Image With Original Name And Time

@lostdreamer_nl Yes I got 'The image failed to upload.' when I tried uploading 'filename.jpg.jpg

I guess there is no fix for that?

dokunbam started a new conversation How To Upload Image With Original Name And Time

I want to upload my images with the original name with time of upload

This is my upload code

 if($request->hasFile('image'))
        {
            $image = $request->file('image');
            $fileName = $request->image->getClientOriginalName();   
            $location = public_path('images/' . $fileName);
            Image::make($image)->resize(500, 400)->save($location);

           $article->image = $fileName;

            //$article->image = $request->filename;
        }

I want to have something like

most-popular-image-2-7-2018-24-23.jpg

The original name is first then followed by the date and time

30 Jan
11 months ago

dokunbam left a reply on User Check In Controller Not Working

Thanks

I hope my code is right

User model

class User extends Authenticatable
{

    public function articles()
    {
        return $this->hasMany('App\Article');
    }
}

Article model

class Article extends Model
{
    //
public function user()
    {
        return $this->belongsTo('App\User');
    }
}

dokunbam started a new conversation User Check In Controller Not Working

I want check in the ProfileController if the Auth::user is logged, then display only the articles belonging to the Authenticated user

I get his error when I run the code

"Undefined property: Illuminate\Pagination\LengthAwarePaginator::$user_id"

ProfileController.php

<?php

namespace App\Http\Controllers;

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


class ProfileController extends Controller
{
    public function profile($username)
    {

        $user = User::whereUsername($username)->first();

        $articles = Article::orderby('id', 'DESC')->paginate(10);

        if($articles->user_id == Auth::id()) {
            return view('user.profile', compact('user', 'articles'));
        }

    }

}

profile.blade

@extends('layouts/app')

@section('content')
    <div class="container">
        <div class="row">
            <div class="col-md-8 col-md-offset-2">
                <div class="panel panel-default text-center">
                    <div class="panel-heading">Dashboard</div>

                    <div class="panel-body">
                        @if (session('status'))
                            <div class="alert alert-success">
                                {{ session('status') }}
                            </div>
                        @endif

                        You are logged
                            <h3>{{$user->name}}</h3>
                                    <h5>{{$user->email}}</h5>
                                            <h6>{{$user->dob->format('l j F Y')}} ({{$user->dob->age}}) years of age</h6>
                                                    <div class="btn btn-success">Follow</div>
                    </div>
                </div>

                <div class="panel panel-default">
                 <div class="panel-heading">Post Feed
                    <span class="pull-right"> <a href="{{URL('/articles/create')}}">Create Article</a></span>
                </div>

                <div class="col-md-8 col-md-offset-2">
                    <div class="panel panel-default">
                        <div class="panel-heading text-center">
                            <span class="text-center">{{Auth::user()->username}}</span>
                        </div>


                        @foreach($articles as $article)
                            @if($article->user_id == Auth::id())
                            <div class="panel-body">{{$article->body}}<a href=""> read more</a> </div>
                        <div class="panel-footer"><i class="glyphicon-heart pull-right clearfix"></i></div>
                        @endif
                        @endforeach
                    </div>
                </div>


            <div class="col-md-6 col-md-offset-4">
                <div class="center-block">

                </div>
            </div>

                </div>

                </div>
            </div>
    </div>
        </div>
    </div>
@endsection

if I remove the if statement in the controller, The view(Frontend) check works fine

26 Jan
11 months ago

dokunbam left a reply on Update Not Working

Yes get redirected back to article index

articles/index.blade.php.

Everything seem working fine but DB is not updated

dokunbam started a new conversation Update Not Working

I can figure this out

Controller

    public function edit($id)
    {
        $article = Article::findOrFail($id);
        return view('articles.edit', compact('article'));
    }

    public function update(Request $request, $id)
    {

        $this->validate($request, [
            'body' => 'required|max:1000|min:20'
        ]);

        $article = Article::find($request['id']);
        $article->body = $request->body;
        $article->live = (boolean)$request->live;
        $article->post_on = $request->post_on;

        $article->save();

        return redirect()->route('articles.index');

    }

edit.blade

 <form class="form-horizontal" method="POST" action="/articles/{{$article->id}}">
                        {{method_field('PUT')}}
                        {{ csrf_field() }}

                        <div class="form-group{{ $errors->has('body') ? ' has-error' : '' }}">
                            <label for="body" class="col-md-2 control-label">Edit Post</label>

                            <div class="col-md-8">
                                <textarea id="body" class="form-control" name="body" rows="5px" value="body" required autofocus>{{ $article->body }}</textarea>

                                @if ($errors->has('body'))
                                    <span class="help-block">
                                        <strong>{{ $errors->first('body') }}</strong>
                                    </span>
                                @endif
                            </div>
                        </div>

                        <div class="form-group{{ $errors->has('live') ? ' has-error' : '' }}">
                            <label for="checkbox" class="col-md-2 control-label">Live</label>

                            <div class="col-md-6">
                                <input type="checkbox" name="live" {{$article->live == 1 ? 'checked' : '' }}>
                                @if ($errors->has('live'))
                                    <span class="help-block">
                                        <strong>{{ $errors->first('live') }}</strong>
                                    </span>
                                @endif
                            </div>
                        </div>

                        <div class="form-group{{ $errors->has('post_on') ? ' has-error' : '' }}">
                            <label for="checkbox" class="col-md-2 control-label">Live</label>

                            <div class="col-md-6">
                                <input type="datetime-local" class="form-control" name="post_on" value="{{$article->post_on->format('Y-m-d\TH:i:s')}}">
                                @if ($errors->has('post_on'))
                                    <span class="help-block">
                                        <strong>{{ $errors->first('post_on') }}</strong>
                                    </span>
                                @endif
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-md-6 col-md-offset-4">
                                <button type="submit" class="btn btn-success pull-right">Update</button>
                            </div>
                        </div>
                    </form>
17 Jan
11 months ago

dokunbam left a reply on Route Not Defined For Logout

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

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
```
09 Jan
1 year ago

dokunbam left a reply on Route Protection With Middleware

@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

@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();
08 Jan
1 year ago

dokunbam left a reply on Route Protection With Middleware

Sorry it http://localhost:8000/dashboard

But I am getting

Route [login] not defined."

dokunbam left a reply on Route Protection With Middleware

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

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

07 Jan
1 year ago

dokunbam started a new conversation Route Protection With Middleware

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

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
06 Jan
1 year ago

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

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

@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

05 Jan
1 year ago

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

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

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

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"

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"

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"

@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'
        ]);
});

04 Jan
1 year ago

dokunbam started a new conversation "Class App\Http\Controllers\UserController Does Not Exist"

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

This is user controller