php – Laravel EventListener doesn't fire-ThrowExceptions

Exception or error: I created an event and listener in Laravel, but the listener doesn’t fire. It does actually fire on my colleague’s machine. That makes me think that the actual code works and that the configuration is in order. Listener: <?php namespace App\Listeners\Consensus; use App\Events\Consensus\ManualGroupChannelNotificationEvent; use Illuminate\Support\Facades\Log; /** * Class ManualGroupChannelNotificationListener * @package App\Listeners\Consensus …

php – Laravel Eloquent – firstOrCreate() on a relationship-ThrowExceptions

Exception or error: When I try the firstOrCreate() on a relationship of another model, it does not work: Client::find($id)->users()->firstOrCreate(array(’email’ => $email)); This returns an error saying Call to undefined method Illuminate\Database\Query\Builder::firstOrCreate() Running this directly on the model User will work though. How to solve: This won’t work, you have to do it manually/directly using User …

php – Laravel Model::create or Model->save()-ThrowExceptions

Exception or error: I’m wondering what approach should I use for storing data in the database; First approach $product = Product::create($request->all()); In my Product model I have my $filable array for mass assigment Second approach $product = new Product(); $product->title = $request->title; $product->category = $request->category; $product->save(); Is any of these two “Better solution”? What should …

php – How do I traverse through model relationships in laravel with dot syntax-ThrowExceptions

Exception or error: I’m trying to traverse through complex eloquent model relationships/attributes, and I’d like to use a simple dot structure to iterate through this, similar to how you can traverse arrays with Arr::get() Example: $data = [ ‘foo’ => [ ‘bar’ => [ ‘key’ => ‘value’ ] ] ]; $value = Arr::get($data, ‘foo.bar.key’); // …