I would like to return to my select all the elements of my ‘categories’ table except the current line. I didn’t find anything about this on the internet, so I’m coming to you. My current item for Select: And this is the head of my categories table: Answer I understand you have a self r…
Tag: laravel
How to make Eloquent model attribute updatable only through public methods?
I want to prevent a model attribute from being directly set from an outside source without going through setters that control the logic. This should not be allowed: You must use some kind of accessor or setter method: But I don’t care how you get the value: How do I enforce that the only way to update t…
Store product multiple colors to the database Laravel
I have a product table which has price, name, stock etc. and color_products table which has color_id, product_id. I want to store a product to the database with selected colors so far I’m getting an error Invalid argument supplied for foreach(). How can I fix this? Controller Blade file Answer try to re…
Call to a member function save() on null in Laravel test
I’m doing a Laravel course on Codecourse. So far I have a Category model: A factory: And a test However, when I run the test, I get: What gives? The course is a couple of years old so I think there’re a couple of differences between Laravel versions, but this seems a bit more fundamental. Answer Y…
Query a model using a relationship
I have a model called unit that has this relationship In the UserData model there is a column called user_id which I am trying to put in my condition in my query. I am trying to do a query like this but there is no user_id column in the Unit table, only though the users relationship Answer Ended up doing
Replace ‘0’ with 1 in phone numbers Laravel
I’m trying to replace users phone numbers to start with 1 instead of 0 but I’m stuck. I have this line $mobileNumber = implode(‘,’, $postData[‘phone’]); which outputs “0445329500,0569075729,…
Laravel multiple filter with search
I want to search service providers and products, and filter by location and by service, or by location and by-products. i am using below code` $results = new ClientProfile; if (request()-&…
Cannot use object of type Illuminate\Http\JsonResponse as array in Laravel
i have data of set like this: I need to fetch the event only and remove the empty events. However first i tried to fetch the events liket this, But it give an error. But it give me an error : Cannot use object of type IlluminateHttpJsonResponse as array Can anyone please help me to resovle the issue? Thank yo…
How can I show images from a Google Drive folder?
I am building a testing website. In login confirmation, I have to show the examinee their pictures, which is already saved in Google Drive Folder. This is what I used to get the file ID. Now in order to preview the image to the page, do I have to download the image (then delete it later) in order to show
OAuth: Proper way to generate/reuse token
This is how I manage the OAuth authentication when a user gives correct credentials: protected function authenticated(Request $request, User $user) { return response()->json([ …