dokunbam

Experience

660

0 Best Reply Awards

  • Member Since 6 Months Ago
  • 0 Lessons Completed
  • 0 Favorites

11th July, 2018

dokunbam left a reply on Use Vuejs On Existing Laravel App • 1 week ago

@andreasbakir Thanks, I will try that

10th July, 2018

dokunbam started a new conversation Use Vuejs On Existing Laravel App • 1 week ago

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?

7th February, 2018

dokunbam left a reply on How To Upload Image With Original Name And Time • 5 months ago

@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 • 5 months ago

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

30th January, 2018

dokunbam left a reply on User Check In Controller Not Working • 5 months ago

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 • 5 months ago

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

26th January, 2018

dokunbam left a reply on Update Not Working • 5 months ago

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 • 5 months ago

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>

17th January, 2018

dokunbam left a reply on Route Not Defined For Logout • 6 months 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 • 6 months 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 • 6 months 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 • 6 months 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 • 6 months ago

Sorry it http://localhost:8000/dashboard

But I am getting

Route [login] not defined."

dokunbam left a reply on Route Protection With Middleware • 6 months 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 • 6 months 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 • 6 months 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 • 6 months ago

Thanks everyone Its working

dokunbam left a reply on Auth::attempt Not Checking If Password Is Correct, But Checking Email • 6 months 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 • 6 months 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 • 6 months 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 • 6 months 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 • 6 months 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 • 6 months 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 • 6 months 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" • 6 months 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" • 6 months 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" • 6 months 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" • 6 months ago

I have included the code

dokunbam started a new conversation "Class App\Http\Controllers\UserController Does Not Exist" • 6 months 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.