I haven’t done PHP in a while so I’m a bit confused why I am getting the error in the title Answer You have to use use, described in docs(http://php.net/manual/en/functions.anonymous.php): Closures may also inherit variables from the parent scope. Any such variables must be declared in the functio…
Tag: laravel
Checking if there is any validation error when using custom form request class
I am using Laravel 5.4. I have a custom form request class where I have my validation rules and messages and I use it in my controller like following : public function store(CustomFormRequest $…
How to use pagination with alaouy/youtube laravel package?
I’m using alaouy/youtube package for one of my projects, Its working just fine, But with this method I can’t use pagination! Is there any way or I’ve to write my own code? There is a vendor folder in my resources with pagination folder but I can’t get work with it! Answer I’m the…
Laravel 5.4 hasManyTrough ‘Call to undefined method IlluminateDatabaseQueryBuilder::hasManyTrough()’
I am struggling to see, where I went wrong. It seams easy, I followed Laravel instructions https://laravel.com/docs/5.4/eloquent-relationships#has-many-through , but clearly I need someone more familar with this sort of code as whenever I try to fetch $stagingsystem-stagesubtype I get error BadMethodCallExcep…
Laravel Validation Rules If Value Exists in Another Field Array
I am working in Laravel 5.4 and I have a slightly specific validation rules need but I think this should be easily doable without having to extend the class. Just not sure how to make this work.. What I would like to do is to make the ‘music_instrument’ form field mandatory if program array contai…
Apply Middleware to all routes except `setup/*` in Laravel 5.4
I’m experimenting with Middleware in my Laravel application. I currently have it set up to run on every route for an authenticated user, however, I want it to ignore any requests that begin with the setup URI. Here is what my CheckOnboarding middleware method looks like: This is being used in my routes …
How to validate an input field if value is not null in Laravel
I am trying to create and update users with laravel 5.4 This is the validation added for create user. It works. On update the password field is not required. But validate the min:6 and confirmed rule if the password field is not null. Tried with sometimes.. but not working.. Answer try using nullable as a rul…
Accessing Laravel .env variables in blade
I am trying to get some API keys which I have stored in my .env file to use in the blade javascript. I have added two keys like: In blade I need to use the Google Maps API and OverheidIO API key. I have tried getting one of the default .env variables just in case I have formatted the custom
preventing abuse of API service usage
I am planning on using Laravel in my next web project, for the backend. Using the Laravel’s built-in functionality I will build an API service. So my main concern now – is about the security of such service. Laravel’s API throttling middleware seems to be an easy to use solution, but it does…
Laravel 5.4 required if validation issue
I have 2 fields, accepts_usd and price_usd. For price usd I have a validation rule: And for accepts_usd: When I want to store data if I set accepts_usd to false it still asks for price_usd. whats the issue here? What am I doing wrong? Answer From laravel docs: required_if:anotherfield,value,… The field …