I am very new to the laravel,i am using l5-repository package for orderBy and sortedBy to sort columns ,while hitting API i am getting following error please help me to resolve the issue
my API URL :-http://localhost.com/v1/domain?limit=250&page=1&orderBy=users|name&sortedBy=desc
You probrably have an error in your table name. For default, laravel will look for cards table name for a model named Card. Also, take a look in your models name. I espect you misstype card.php because it should be Card.php. Laravel uses a lot of psr convention and Eloquent (who deal with relationships and that stuff). If you are not well versed into it, take a look in how to name classes. As Alireza said, take a look in the Laravel's documentation, it is awesome and complete. When you have a one to many realtionship, one of they should have a hasMany(...) instead belongsTo(....)
Related
i am getting data from different different tables and i displayed all those in one section that section contains search button also, i want to add another resource field as a searchable item in nova ,i am trying to add based on the relation of the particular table but it's throwing an error undefined column, How to add please help..
public static $searchable=['id','name','account.type'];
Basically, the search by relationship is not possible through Nova.
A package well made for your needs is this one: LaravelNovaSearch
This package includes both relationship search but also has other useful features making the search much more comprehensive.
Another package, which I have not personally tested, but which seems to be useful for your needs: NovaSearchRelations
My advice is to use LaravelNovaSearch, more maintained and more complete.
I have been using Laravel for a couple weeks now and I love the framework. However, with models is there any actual robust system? Creating models, like the user model, just seems to be string arrays of what you do and do not want modified in queries. The place I see validation of the models is in the controller (through $this->validate()) and/or migrations creating the tables.
I just wanted to know if there is a certain place I am missing or not implementing. My brain is referencing something like ASP.NET's decorators that add validation to data models. Thank you!
When looking for a fix for an issue I had dealing with Datatables, I found this interesting syntax but I cannot find anything on the Laravel documentation to help me understand what's going on but I'd like to learn its useability.
This is the code snippet:
return $model->select('sessions.*')
->with('employee:id,name');
It’s mentioned in the docs: https://laravel.com/docs/8.x/eloquent-relationships#eager-loading-specific-columns
You may not always need every column from the relationships you are retrieving. For this reason, Eloquent allows you to specify which columns of the relationship you would like to retrieve:
$books = Book::with('author:id,name')->get();
I have created a model with a relationship to another model.
I want to send an email with the entry information, afterCreate seems like the place to do so. But it doesn't contain my relationship fields on the model object.
We have an issue about that on GitHub, there is currently not workaround about that.
Alex is re-writing the logic behind the life cycle function, so lot of issue should be fixed on that after the release of the new system.
As of Strapi 3.0.0, the model lifecycles have changed and now afterCreate does contain relationships.
I have a relationship as Restaurant has Many Jobs
I have properly set the methods in Restaurant and Jobs model.
I am creating a query where the job.status is in active or upcoming and with that I need restaurant data too.
Below is my code:
Job::whereIn("status", ['upcoming', 'active'])->with(['restaurant'])->get();
with this I am getting restaurant as null
As I am novice in Laravel, I tried the other way around also.
Job::with(['restaurant'])->whereIn("status", ['upcoming', 'active'])->get();
But it gave the same result.
However, if I use where it works properly.
Below is the code which is working and providing restaurant data.
Job::where("end_date_time", '>=', $currentDate->format('Y-m-d H:i:s'))->with(['restaurant'])->get();
I saw the documentation and I found that whereIn is Collections method, so is it something that it will not work if we have with?
I searched on google any example of whereIn and with, but I didn't found any.
May I am doing some conceptual mistake in understanding whereIn and with
Your help is much appreciated.
Thanks.