Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mattdj's avatar

FindofFail and no php errors

Hi all, I am a new in Laravel and I have some begginer questions:

  1. PhpStorm showed me that I have no FindOrFail,FirstorFail,find methods, --> only FindOrNew, FirstOrNew etc. What is wrong? Where I make mistake? I try to search in Model.php but with no success.
  2. Laravel show me errors like NotFoundException but no php errors. Nginx works fine, local environment and debug = true.

Thx in advance.

0 likes
9 replies
d3xt3r's avatar

Laravel heavily utilizes magic methods which makes it impossible for ide to give proper results. Use https://github.com/barryvdh/laravel-ide-helper to minimize the situation.

Even with above there will be situation where ide will show warning, if you are absolutely sure, ignore them

mattdj's avatar

thx for response, I already have IDE helper... :(

d3xt3r's avatar

Sadly, i dont understand the question then. Are you complaining that you couldn't find these methods in Model class (because they are part of query builder Illuminate\Database\Eloquent\Builder) or you are complaining that PHP storm couldn't find these methods.

Eloquent model uses __call magic method to construct the query for you which is confusing for the ide. If you want PHP storm to stop complaining add the PHPDocs to your class

/**
 * @method static findOrFail($id, $columns = ['*'])
* ... what ever else 
*/

Your NotFoundException has nothing to do with these methods not found.

mattdj's avatar

Ok, so to make more simply:

OrdersController

namespace App\Http\Controllers;

use App\Order; use App\User; use Illuminate\Http\Request; use App\Http\Requests; use App\Http\Requests\CreateOrderRequest; use App\Http\Controllers\Controller; use Auth;

class OrdersController extends Controller { /** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { return 'sth'; }

/**
 * Show the form for creating a new resource.
 *
 * @return \Illuminate\Http\Response
 */
public function create()
{
    return view('orders.create') ;
}

/**
 * Store a newly created resource in storage.
 *
 * @param  \Illuminate\Http\Request  $request
 * @return \Illuminate\Http\Response
 */
public function store(CreateOrderRequest $request)
{
    $order = new Order($request->all());
    Auth::user()->orders()->save($order);

    return redirect('orders');
}

/**
 * Display the specified resource.
 *
 * @param  int  $id
 * @return \Illuminate\Http\Response
 */
public function show($id)
{
    $order = Order::findOrFail($id);

    return view('order.show',compact($order));
}

/**
 * Show the form for editing the specified resource.
 *
 * @param  int  $id
 * @return \Illuminate\Http\Response
 */
public function edit($id)
{
    $order = Order::find($id);
    return $order;
}

/**
 * Update the specified resource in storage.
 *
 * @param  \Illuminate\Http\Request  $request
 * @param  int  $id
 * @return \Illuminate\Http\Response
 */
public function update(Request $request, $id)
{
    //
}

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

}

Model: Order

namespace App;

use Carbon\Carbon; use Illuminate\Database\Eloquent\Model;

class Order extends Model { protected $fillable = ['tresc_zlecenia', 'max_cena', 'max_czas_wykonania'];

// zamiana na Carbon ! :)
protected $dates = ['max_czas_wykonania'];

public function scopePublished($query)
{
    $query->where('czas_wykonania','<=',Carbon::now()->get());
}

public function setPublishedAtAttribute($date)
{
    $this->attributes['max_czas_wykonania'] = Carbon::parse($date);
}

}

Routes:

/* |-------------------------------------------------------------------------- | Application Routes |-------------------------------------------------------------------------- | | Here is where you can register all of the routes for an application. | It's a breeze. Simply tell Laravel the URIs it should respond to | and give it the controller to call when that URI is requested. | */

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

Route::resource('orders','OrdersController');

Route::controllers([

    'auth' => 'Auth\AuthController',
    'password' => 'Auth\PasswordController',
]

);

My problem I go to: http://localhost/orders/1/edit And I have no results. I search and everything looks like I don't have method like find, findorfail !!!

Why ?

d3xt3r's avatar

Do you have something in your order table that has id 1. Believe me you have methods like like find, findorfail :) Can you share the error that you get .

1 like
mattdj's avatar

Ok, I found solution: I name my key in table id_sth ---> when I put id is all OK. I wonder how Can I change that.. ? This is my first question.

Second, much more important: Why Laravel don't show me php errors? Should return null or mistake... ? it is for me really frustrating.

My .env APP_ENV=local APP_DEBUG=true APP_KEY=pCCyTjwA19Fr6ElV22bVairbAtld0dF3

DB_HOST=localhost DB_DATABASE=laravel_267999 DB_USERNAME=root DB_PASSWORD= password

CACHE_DRIVER=file SESSION_DRIVER=file QUEUE_DRIVER=sync

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

d3xt3r's avatar

@mattdj

1> You can use any name as primary key just let Laravel know what is it. Change the below in your model class

protected $primaryKey = 'your-key-name';

2> What PHP errors ?

1 like
mattdj's avatar
  1. works
  2. all php erors f.e. in view I have done sth wrong - PhpStorm showed me errors but when I am trying to open in browser - I have only empty page.

Please or to participate in this conversation.