In your Laravel controller or somewhere in your code you probably have a try/catch like this:
useApp\Exceptions\FailedRequestException;classApiController{publicstaticsendRequest(){$api=newSomeApi();try{$api->sendRequest();returnresponse()->json(['data'=>$api->getData(),]);}catch(FailedRequestException$e){returnresponse()->json(['error'=>'Failed to send API request',]);}}}
If you ever used Eloquent events, you are probably aware of special boot() static method in Eloquent models.
This method allows you to hook into special events by running given functions.
Here’s an example, let’s say we have a Post model and when we are creating a new post, model needs to generate slug attribute based on name.
There are known ways in Laravel to measure database performance, keep query count to minimum, prevent “N+1” issues.
Tools like laravel-debugbar is a must-have to see what’s happening with every request.
Laravel testing tools are very powerful for doing endpoint (feature) tests. Let’s say we have an endpoint which accepts requests as JSON. Take this simple test as an example:
In Vue.js creating nested components and passing data between them is pretty straight forward thanks to property binding and event emitting. Take this as an example.
When uploading files in Laravel application, request validation gives us good support for validating uploaded files. You can define if uploaded file needs be an image, you can set maximum size in kilobytes, you can filter out which mime types or file extensions are accepted.
When working with form elements, Vue’s v-model directive comes useful for 2-way data binding.
But when you create your own custom form components and wrap input elements inside, it becomes hard to maintain the same 2-way binding with custom form component and parent component.