I have the below tables posts – id – name categories – id – name category_post – post_id – category_id Post.php Category.php A post may contain many categories. I want to query all posts related to the categories of any given post in the least number of database queries. For example, If a post belongs to three categories, I want
Tag: laravel
laravel – Can I add new items to an array that already has some existing items?
var_export($response) is an array like below: The below code gives a result like this: “data”: 3. I wanted add a new item called points with the $response array, into all elements. But here, it overwrites the existing array. How can I achieve this? Expected output: Answer As mentioned, array_push() returns the new number of elements in the array. That’s why
Change login system by API in Laravel 8
I make my first app with API. I am beginner in Laravel and php. I have this migration: and this is my AuthController: Login work’s fine. In addition to the login and password, I need to verify the status column. If status = 1 – then login is possible. How can I do this? Please help me 🙂 How can
How to integrate React App With Laravel Sanctum on Apache2
I use React App on localhost:3000 For Laravel API I use apache2 from Laradock and site is: site.localhost To authorize users I use Sanctum Problem is I can not get cookies from sanctum/csrf-cookie (i got them in response header but they are not appear in cookies) and then got 419 code when i try to login via API My .env
How can I solve this “Undefined variable $last_number” from return line in laravel 8
I am using Laravel 8 to create an application. Here I need to Generate an Order Number for every order. For this, I use Helper and write this code. It works the very first time, from the second time it shows “Undefined variable $last_number” from return line. from my controller I use this: Answer I think your code should be
How can i customize laravel middleware ‘auth:api’?
I want to customize my auth middleware that secure my endpoint. for example, i want to accept requests that have specific bearer token. how can i do? i’m using dingo api library. Answer Go to kernel.php file in HTTP directory. You’ll see something like this. Find the ExampleClass and read its handle method. After you figure it out how it
Laravel Eloquent return conditionally when first condition not exists return another
i use Eloquent for get Multilanguage post title. this return english title, but some times the english title not exist so i want to return title in another language . i mean when use getTitle_en to get engish title ([‘cat’ => ‘title’, ‘meta_name’ => ‘en’]) , if it’s not exist return title in another language like “nl” and again if
Laravel yajrabox relation sort
I have a project with laravel and datatable using yajrabox, it stuck in relationship sort this is my kabupaten datatable class and this is my action column. provinsi model and kabupaten model my question are why $id in kabupaten.action return provinsi.id instead of kabupaten.id and i have try The $id return kabupaten.id but when I try to sort column, it
Laravel could not find driver Cpanel
I deployed my Laravel project on Cpanel but there’s an error “could not find driver(SQL)” I’m using Mysql database in Cpanel, and I have checked pdo_mysql in PHP extension. but when I looked on phpinfo(); and find pdo_mysql, the result is 0/0 How to fix this? Thanks in advance Answer Thanks for your reply. The culprit is my PHP version
Laravel variable not getting passed to route
In my page, I have the following anchor: which links to the following function in the controller: and then the blogtitles/edit.blade.php file simply contains: However, in the edit.blade.php, the variable ‘$blogTitle` is empty, even though I know that it isn’t empty in the original page where it is passed from. Any idea at all what is going wrong? I have