Method App\Http\Controllers\UserController::validate does not exist. There is the problem with validation email but i cant find solution

Published 1 month ago by Nerke

Sergiu17
Sergiu17
1 month ago (177,710 XP)

Which version of the Laravel are you using?

Nerke

5.6.23

Cronix
Cronix
1 month ago (727,800 XP)

show your code?

Nerke
Cronix
Cronix
1 month ago (727,800 XP)

```

code

```

Nerke
<?php

namespace App\Http\Controllers;
use App\User;
use Illuminate\Http\Request;

use Illuminate\Routing\Controller;


class UserController extends Controller
{
    public function getSingup(){
        return view('user.singup');
    }
    public function postSingup(Request $request){
         $this->validate(request(),[
            'email'=> 'required|email|unique:users',
            'password'=> 'required|min:4'
        ]);
        $user = new User([
            'email' => $request->input('email'),
            'password' => bcrypt($request->input('password'))
        ]);
        $user -> save();

        return redirect()->route('product.index');
    }
}
Cronix
Cronix
1 month ago (727,800 XP)

try removing this

use Illuminate\Routing\Controller;

You're in the App\Http\Controllers; namespace, so you want to just extend the base controller in that same namespace.

Cronix
Cronix
1 month ago (727,800 XP)

Or if for some reason you don't want to extend laravels base controller (which is loading the validation, etc), you can look at theirs (Controller.php in same dir).

use Illuminate\Foundation\Validation\ValidatesRequests;

class UserController extends Controller
{
    use ValidatesRequests;

    // rest of your code
}
Nerke

No the same bug... :(

Snapey
Snapey
1 month ago (993,685 XP)

show your revised code please

Nerke
<?php

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


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

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

Snapey
Snapey
1 month ago (993,685 XP)

Why have you posted the migration?

Nerke

@extends('layouts.master')

@section('content')

    <div class="container-fluid">
    <div class="center-block">
        <div class="align-content-center">
    <div class="col-md-2 col-md-offset-1">

        <h1>Sing Up</h1>
        @if(count($errors)> 0)
            <div class="alert alert-danger">
                @foreach($errors->all() as $error)
                    <p>{{ $error }}</p>
                    @endforeach
            </div>
        @endif

        <form action="" method="post">
            {{ csrf_field() }}
            <div class="form-group ">
                <label for="email">E-Mail</label>
                <input type="text" id="email" name="email" class="form-control">
            </div>
            <div class="form-group ">
                <label for="password">Password</label>
                <input type="password" id="password" name="password" class="form-control">
            </div>
            <button type="submit" class="btn btn-primary">Sing Up</button>
        </form>
        </div>
    </div>

    </div>
    </div>
@endsection

saurabhd

You should try this:

<?php

namespace App\Http\Controllers;
use App\User;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\Route;


class UserController extends Controller
{
    public function getSingup(){
        return view('user.singup');
    }
    public function postSingup(Request $request){
         $this->validate($request,[
            'email'=> 'required|email|unique:users',
            'password'=> 'required|min:4'
        ]);

         $input = $request->all();
        $user = new User($input);
        $user -> save();

        return redirect()->route('product.index');
    }
}

dawoodiddris

try using this method of validating $postsignedup = request()->validate(['email' => 'required','password' => 'required'])

dd($postsignedup)

Please sign in or create an account to participate in this conversation.