3

I'm beginner in laravel. What I tried is composer dump-auto, but did not work.

This Code is in Laravel 5.0 Every answer will be appreciated.

<?php namespace App\Http\Controllers;

use App\Http\Requests;
use App\Http\Controllers\Controller;

use Illuminate\Http\Request;

use View,
    Response,
    Validator,
    Input,
    Mail,
    Session;



class UserController extends Controller {

    /**
     * Display a listing of the resource.
     *
     * @return Response
     */
    public function index()
    {
        return view('pages.default');
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return Response
     */
    public function insert()
    {

        $

        $user = User::create(['u_name' => 'inputName', 'u_eml' => 'inputMail', 'u_contact' => 'inputContact']);

    }

    /**
     * Store a newly created resource in storage.
     *
     * @return Response
     */
    public function store()
    {
        //
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  int  $id
     * @return Response
     */
    public function update($id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return Response
     */
    public function destroy($id)
    {
        //
    }

}

This is my Model: User.php

<?php namespace App;

use Illuminate\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;

class User extends Model implements AuthenticatableContract, CanResetPasswordContract {

    use Authenticatable, CanResetPassword;

    protected $table = 'user';
    public $timestamps = false;    
}

3 Answers 3

7

Just add use App\User in your top list - like this:

use App\User;

Or you can change your controller code to be \App\User::create(... (notice the \ at the beginning)

Sign up to request clarification or add additional context in comments.

4 Comments

Actually it's use App\User and \App\User::create(...
Sigh... one day I'll actually get an answer right :)
@TheShiftExchange so everytime you call a model in Laravel 5 in a file you need to have "use App*MODEL LOCATION*"?
@TheShiftExchange ah Thank you very much. I am brand new to laravel and the docs didn't mention that so i was struggling to figure out why i was getting User class not found error on php artisan db:seed
0

Simply add

use App\user;

before the class declaration

Comments

0

use App\User in the controller like this.

<?php namespace App;

use Illuminate\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
use App\User;

 class User extends Model implements AuthenticatableContract,CanResetPasswordContract {

use Authenticatable, CanResetPassword;

protected $table = 'user';
public $timestamps = false;    
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.