Laravel eloquent and query builder Eager Loading Multiple Relationships with where clause - laravel

I have few tables, they are room_types, rooms, rates, prices I want to get
room_types with rooms with rates and rates with prices where(price room_type_id = room_types.id) . I tried to do something like that
$roomTypeIds = [];
foreach ($hotel->rooms as $room) {
array_push($roomTypeIds, $room->roomtype->id);
}
$roomsByType = RoomType::with(['rooms' => function ($query) {
$query->with(['rates' => function($q) {
$q->with('policy', 'prices');
}]);
}])->whereIn('id', array_unique($roomTypeIds))->get();
but in this example Im getting all prices but I want to get only that prices which room_type_id IS EQUAL TO current room_type.id. So for that I have tried to do some think like this
$roomsByType = RoomType::with(['rooms' => function ($query) {
$query->with(['rates' => function($q) {
$q->with(['policy', 'prices' => function($q1) {
$q1->where('room_type_id', '');
}]);
}]);
}])->whereIn('id', array_unique($roomTypeIds))->get();
But I don't know what to put in where clouse. So are there any way to do this?
And result that I want to have is
[
{
"id": 2,
"name": "Twin/Double",
"created_at": "2017-12-11 08:56:16",
"updated_at": "2017-12-11 08:56:16",
"rooms": [
{
"id": 4,
"hotel_id": 1,
"room_type_id": 2,
"custom_name": null,
"room_name": "3",
"number_of_type": 2,
"number_of_bedrooms": null,
"number_of_livingrooms": null,
"number_of_bathrooms": null,
"created_at": "2017-12-12 06:37:34",
"updated_at": "2017-12-12 06:37:34",
"rates": [
{
"id": 4,
"user_id": 19,
"custom_name": "Default rate",
"price": 0,
"automatic": 0,
"rate_id": null,
"operand": null,
"amount": null,
"currency": null,
"policy_id": 1,
"meal_types": null,
"created_at": "2017-12-12 09:27:31",
"updated_at": "2017-12-12 09:27:29",
"pivot": {
"room_id": 4,
"rate_id": 4
},
"policy": {
"id": 1,
"name": "Free cancellation before 3 / 60 %",
"hotel_id": 1,
"free": 1,
"before_day": 3,
"before_day_price": 60,
"until_day_price": null,
"created_at": "2017-12-08 14:03:31",
"updated_at": "2017-12-08 14:03:31"
},
"prices": [
{
"id": 1,
"rate_id": 4,
"room_type_id": 2,
"from": "2017-12-01 09:18:46",
"to": "2017-12-18 09:18:57",
"amount": 100,
"created_at": "2017-12-18 09:19:11",
"updated_at": "2017-12-18 09:19:12"
},
{
"id": 3,
"rate_id": 4,
"room_type_id": 3,
"from": "2017-12-22 10:36:30",
"to": "2017-12-30 10:36:35",
"amount": 3000,
"created_at": null,
"updated_at": null
}
]
}
]
},
{
"id": 5,
"hotel_id": 1,
"room_type_id": 2,
"custom_name": null,
"room_name": "3",
"number_of_type": 2,
"number_of_bedrooms": null,
"number_of_livingrooms": null,
"number_of_bathrooms": null,
"created_at": "2017-12-12 06:37:34",
"updated_at": "2017-12-12 06:37:34",
"rates": [
{
"id": 4,
"user_id": 19,
"custom_name": "Default rate",
"price": 0,
"automatic": 0,
"rate_id": null,
"operand": null,
"amount": null,
"currency": null,
"policy_id": 1,
"meal_types": null,
"created_at": "2017-12-12 09:27:31",
"updated_at": "2017-12-12 09:27:29",
"pivot": {
"room_id": 5,
"rate_id": 4
},
"policy": {
"id": 1,
"name": "Free cancellation before 3 / 60 %",
"hotel_id": 1,
"free": 1,
"before_day": 3,
"before_day_price": 60,
"until_day_price": null,
"created_at": "2017-12-08 14:03:31",
"updated_at": "2017-12-08 14:03:31"
},
"prices": [
{
"id": 1,
"rate_id": 4,
"room_type_id": 2,
"from": "2017-12-01 09:18:46",
"to": "2017-12-18 09:18:57",
"amount": 100,
"created_at": "2017-12-18 09:19:11",
"updated_at": "2017-12-18 09:19:12"
},
{
"id": 3,
"rate_id": 4,
"room_type_id": 3,
"from": "2017-12-22 10:36:30",
"to": "2017-12-30 10:36:35",
"amount": 3000,
"created_at": null,
"updated_at": null
}
]
}
]
}
]
}
]

Look at the whereHas function instead of using with
https://laravel.com/docs/5.5/eloquent-relationships#querying-relations

Related

Laravel : How to randomize the query of the Quiz with choices

I'm planning to randomize the order of my query on quiz_question and choices but the quiz_question is the only one who gets randomized but the choices are still the same.
This is my code :
class QuestionByQuizID extends Controller
{
public function index(int $quiz_id){
$questions = quizQuestions::where('quiz_id', '=', $quiz_id)->with(['choices'])->inRandomOrder()->get();
if(is_null($questions)){
return response()->json('Record not found!', 401);
}
return response(['message'=>"Questions displayed successfully",
'quizQuestions'=>$questions],200);
}
}
This is the sample query using postman
"message": "Questions displayed successfully",
"quizQuestions": [
{
"id": 580,
"quiz_id": 36,
"question_num": 10,
"question_content": "What Are Those",
"correct_answer": null,
"created_by": null,
"updated_by": null,
"created_at": "2022-01-12T12:58:27.000000Z",
"updated_at": "2022-01-12T12:58:27.000000Z",
"question_image": null,
"tagalog_question": "Ano yan!",
"choices": [
{
"id": 1861,
"quiz_questions_id": 580,
"option": "choice 1",
"remarks": 0,
"created_at": "2022-01-12T12:58:27.000000Z",
"updated_at": "2022-01-12T12:58:27.000000Z",
"choices_image": null,
"tagalog_choices": "tagalog"
},
{
"id": 1862,
"quiz_questions_id": 580,
"option": "choice2",
"remarks": 0,
"created_at": "2022-01-12T12:58:27.000000Z",
"updated_at": "2022-01-12T12:58:27.000000Z",
"choices_image": null,
"tagalog_choices": "tagalog"
},
{
"id": 1863,
"quiz_questions_id": 580,
"option": "choice3",
"remarks": 0,
"created_at": "2022-01-12T12:58:27.000000Z",
"updated_at": "2022-01-12T12:58:27.000000Z",
"choices_image": null,
"tagalog_choices": "tagalog"
},
{
"id": 1864,
"quiz_questions_id": 580,
"option": "choice4",
"remarks": 1,
"created_at": "2022-01-12T12:58:27.000000Z",
"updated_at": "2022-01-12T12:58:27.000000Z",
"choices_image": null,
"tagalog_choices": "tagalog"
}
]
can anyone help me? thanks in advance.
You can do additional query conditions for the choices relationship:
$questions = quizQuestions::where('quiz_id', '=', $quiz_id)->with(['choices' => function($query){
$query->inRandomOrder();
}])->inRandomOrder()->get();
https://laravel.com/docs/8.x/eloquent-relationships#constraining-eager-loads

Issue trying to assert Response structure based on type

Laravel Version: 6.20.30
PHP Version: 7.2.8
Database Driver & Version: Mysql 5.7
Description:
The issue I'm facing is that I need to test the structure of a response in which some properties are look-alike
Steps To Reproduce:
this is the response to test against :
[
{
"id": 1,
"product_id": 1,
"section_id": 1,
"image_id": null,
"html_id": 1,
"index": 0,
"name": "zip_2MB",
"description": "Error ex sed numquam et odit minima quia sunt. Praesentium in ea numquam. Alias ut pariatur voluptates modi velit veniam aspernatur accusantium. Aut facilis minus reprehenderit praesentium eum.",
"title": "Slide #53",
"backup": false,
"required": true,
"emailable": 0,
"type": 0,
"asset_id": null,
"thumb_id": null,
"image": null,
"html": {
"id": 1,
"product_id": 1,
"zip_id": 1,
"thumb_id": 1,
"name": "zip_2MB",
"rank": 0,
"created_at": "2021-08-11 13:24:42",
"updated_at": "2021-08-11 13:24:42",
"deleted_at": null,
"thumb": {
"id": 1,
"user_id": null,
"key": "archive/zip_2MB.zip",
"bucket": "symmetryk-assets-testing",
"region": "eu-west-2",
"cdnURL": "https://symmetryk-assets-testing.s3.eu-west-2.amazonaws.com/archive/zip_2MB.zip",
"size": 2036861,
"size_thumb": 0,
"size_preview": 0,
"mime_type": "application/zip",
"extension": "zip",
"width": null,
"height": null,
"duration": null,
"viewed": null,
"created_at": "2021-08-11 13:24:42",
"updated_at": "2021-08-11 13:24:42",
"deleted_at": null
},
"html": {
"id": 1,
"user_id": null,
"key": "archive/zip_2MB.zip",
"bucket": "symmetryk-assets-testing",
"region": "eu-west-2",
"cdnURL": "https://symmetryk-assets-testing.s3.eu-west-2.amazonaws.com/archive/zip_2MB.zip",
"size": 2036861,
"size_thumb": 0,
"size_preview": 0,
"mime_type": "application/zip",
"extension": "zip",
"width": null,
"height": null,
"duration": null,
"viewed": null,
"created_at": "2021-08-11 13:24:42",
"updated_at": "2021-08-11 13:24:42",
"deleted_at": null
}
}
},
{
"id": 2,
"product_id": 1,
"section_id": 1,
"image_id": 2,
"html_id": null,
"index": 1,
"name": "file_example_JPG_500kB",
"description": "Et voluptatem et corporis in.",
"title": "Slide #78",
"backup": false,
"required": false,
"emailable": 0,
"type": 2,
"asset_id": 2,
"thumb_id": 2,
"image": {
"id": 2,
"product_id": 1,
"image_id": 2,
"thumb_id": 2,
"name": "file_example_JPG_500kB",
"rank": 1,
"created_at": "2021-08-11 13:25:23",
"updated_at": "2021-08-11 13:25:23",
"deleted_at": null,
"thumb": {
"id": 2,
"user_id": null,
"key": "image/file_example_JPG_500kB.jpeg",
"bucket": "symmetryk-assets-testing",
"region": "eu-west-2",
"cdnURL": "https://symmetryk-assets-testing.s3.eu-west-2.amazonaws.com/image/file_example_JPG_500kB.jpeg",
"size": 555181,
"size_thumb": 0,
"size_preview": 0,
"mime_type": "image/jpeg",
"extension": "jpeg",
"width": null,
"height": null,
"duration": null,
"viewed": null,
"created_at": "2021-08-11 13:25:23",
"updated_at": "2021-08-11 13:25:23",
"deleted_at": null
},
"image": {
"id": 2,
"user_id": null,
"key": "image/file_example_JPG_500kB.jpeg",
"bucket": "symmetryk-assets-testing",
"region": "eu-west-2",
"cdnURL": "https://symmetryk-assets-testing.s3.eu-west-2.amazonaws.com/image/file_example_JPG_500kB.jpeg",
"size": 555181,
"size_thumb": 0,
"size_preview": 0,
"mime_type": "image/jpeg",
"extension": "jpeg",
"width": null,
"height": null,
"duration": null,
"viewed": null,
"created_at": "2021-08-11 13:25:23",
"updated_at": "2021-08-11 13:25:23",
"deleted_at": null
}
},
"html": null
}
]
this is can be returned from a route for easy testing.
$request = $this->get('/dummy-url-to-return-the-response');
$request
->assertJsonStructure(
[
'*' => [
'id',
'product_id',
'section_id',
'image_id',
'html_id',
'index',
'name',
'description',
'title',
'backup',
'required',
'emailable',
'type',
'asset_id',
'thumb_id',
'image' => [
'*' => [
'id',
'product_id',
'image',
'thumb'
]
],
'html' => [
'*' => [
'id',
'product_id',
'image',
'thumb'
]
]
]
]
)
If an object have an html object, the image object is null and vis versa.
Keep in mind that the structure was truncated for easier follow so assuming that I am writing this correctly, this is the message I keep getting.
Argument #2 of PHPUnit\Framework\Assert::assertArrayHasKey() must be an array or ArrayAccess

Laravel: Advanced Polymorphic relationship

I am attempting to scope an answer to a User or Project via a polymorphic relationship via multiple levels but I am having some trouble getting my head around it.
It's tricky to explain, but I will show you what I have at the moment, minus the Answer model/relationship.
I have a Category and a Role model. These are in a belongsTo relationship (a role belongs to a category).
I also have a Question model, this also has a belongsTo relationship with a Role (a question belongs to a role).
I have created a roleables polymorphic relationship, allowing me to assign roles to either a User or a Project.
All of this is working as expected. I am able to return the assigned roles via my endpoint user/1/roles or project/1/roles, and in this endpoint, I am able to return the questions for that role (see example output below).
{
"data": [
{
"id": 20,
"name": "Actor",
"entity_id": 1,
"category_id": 3,
"questions": [
{
"id": 20,
"role_id": 20,
"field_type": "text",
"field_name": "Height",
"field_default_value": null,
"field_validation_rules": "required,string,max:5",
"field_options": false,
"order": 0
},
{
"id": 21,
"role_id": 20,
"field_type": "text",
"field_name": "Weight",
"field_default_value": null,
"field_validation_rules": "required,string,max:5",
"field_options": false,
"order": 1
},
{
"id": 22,
"role_id": 20,
"field_type": "select",
"field_name": "Race",
"field_default_value": null,
"field_validation_rules": "required,string,max:255",
"field_options": [
{
"id": "white",
"name": "White"
},
{
"id": "mixed",
"name": "Mixed"
}
],
"order": 2
},
{
"id": 23,
"role_id": 20,
"field_type": "select",
"field_name": "Gender",
"field_default_value": null,
"field_validation_rules": "required,string,max:255",
"field_options": [
{
"id": "male",
"name": "Male"
},
{
"id": "female",
"name": "Female"
},
{
"id": "other",
"name": "Other"
}
],
"order": 3
}
],
"created_at": {
"date": "2019-07-24 13:35:33.000000",
"timezone_type": 3,
"timezone": "UTC"
},
"updated_at": {
"date": "2019-07-24 13:35:33.000000",
"timezone_type": 3,
"timezone": "UTC"
},
"entity_type": "user"
},
{
"id": 23,
"name": "Singer",
"entity_id": 1,
"category_id": 3,
"questions": [
{
"id": 26,
"role_id": 23,
"field_type": "text",
"field_name": "Description",
"field_default_value": null,
"field_validation_rules": "required,string,max:255",
"field_options": false,
"order": 0
}
],
"created_at": {
"date": "2019-07-24 13:35:33.000000",
"timezone_type": 3,
"timezone": "UTC"
},
"updated_at": {
"date": "2019-07-24 13:35:33.000000",
"timezone_type": 3,
"timezone": "UTC"
},
"entity_type": "user"
},
{
"id": 32,
"name": "Console Operator",
"entity_id": 1,
"category_id": 5,
"questions": [
{
"id": 35,
"role_id": 32,
"field_type": "text",
"field_name": "Description",
"field_default_value": null,
"field_validation_rules": "required,string,max:255",
"field_options": false,
"order": 0
}
],
"created_at": {
"date": "2019-07-24 13:35:33.000000",
"timezone_type": 3,
"timezone": "UTC"
},
"updated_at": {
"date": "2019-07-24 13:35:33.000000",
"timezone_type": 3,
"timezone": "UTC"
},
"entity_type": "user"
},
{
"id": 60,
"name": "Composer",
"entity_id": 1,
"category_id": 7,
"questions": [
{
"id": 63,
"role_id": 60,
"field_type": "text",
"field_name": "Description",
"field_default_value": null,
"field_validation_rules": "required,string,max:255",
"field_options": false,
"order": 0
}
],
"created_at": {
"date": "2019-07-24 13:35:33.000000",
"timezone_type": 3,
"timezone": "UTC"
},
"updated_at": {
"date": "2019-07-24 13:35:33.000000",
"timezone_type": 3,
"timezone": "UTC"
},
"entity_type": "user"
}
]
}
The problem that I am trying to get my head around is Answers to the questions. Just a little background, which may help me explain this in writing:
In the front-end, I have a page in which the user can update their information, on this page they also have the ability to assign themselves some roles. When the click on a role the list of questions is displayed and they have the ability to answer them.
The same is also true for a Project. A user can create projects, and have the ability to assigned roles and answer the relevant questions.
So, I guess I will need to create a new table in the database to store the answers.
The question is how/what relationship should this new answers table have to the question, user/project in order to get all the roles, questions and any answers scoped to the entity (user/project) and it's roles?
I would love the each role in the output from my user/1/roleendpoint to look more like the following (notice the new answers key in questions):
{
"id": 60,
"name": "Composer",
"entity_id": 1,
"category_id": 7,
"questions": [
{
"id": 63,
"role_id": 60,
"field_type": "text",
"field_name": "Description",
"field_default_value": null,
"field_validation_rules": "required,string,max:255",
"field_options": false,
"order": 0,
"answers": { ... }
}
],
"created_at": {
"date": "2019-07-24 13:35:33.000000",
"timezone_type": 3,
"timezone": "UTC"
},
"updated_at": {
"date": "2019-07-24 13:35:33.000000",
"timezone_type": 3,
"timezone": "UTC"
},
"entity_type": "user"
}

Laravel apply sortBy to a related models collection

I am using the below code:
$greatDeals = $greatDealsinitial->sortBy(function ($deal, $key) {
return $deal->hotel->room[0]->price;
});
Here room is an array, I want to sort this collection by price in the room array.
But I can't use return $row->hotel->room->price;
So how can I sort this?
my collection :
[
{
"id": 2,
"hotel_id": 1,
"deal_code": "sfg",
"date": "2018-04-13 00:00:00",
"discount": 12,
"status": 1,
"created_at": "2018-04-13 11:21:18",
"updated_at": "2018-04-13 11:21:18",
"deleted_at": null,
"client_id": 1,
"hotel": {
"id": 1,
"name": "Aloft Dongguan Songshan Lake",
"address": "Dongguan, China, 511700",
"phone": "76982106666",
"country": "101",
"country_name": "India",
"state": "35",
"state_name": "Tamil Nadu",
"city": "3551",
"city_name": "Abiramam",
"area": null,
"pincode": "511700",
"nearest_airport": null,
"nearest_railway": null,
"star": null,
"check_in": null,
"check_out": null,
"lat": "22.929869",
"lng": "113.89232800000002",
"description": null,
"astatus": "1",
"status": "0",
"created_at": "2018-04-13 10:27:30",
"updated_at": "2018-04-13 10:27:48",
"client_id": 1,
"hotel_age": null,
"hotel_privilege": "asdf",
"departure": "sdaf",
"checkout_fee": "asdf",
"book_policy": "sadf",
"hotel_secured": null,
"hotel_pets": null,
"hotel_other": null,
"room": [
{
"id": 3,
"roomtype_id": 2,
"room_count": null,
"max_adult": 2,
"max_children": 1,
"capacity": 3,
"room_number": null,
"floor": null,
"number": null,
"name": null,
"city_name": "Abiramam",
"city": 3551,
"price": "200.00",
"extra_bed_price": null,
"astatus": "1",
"status": "0",
"created_at": "2018-04-13 12:37:11",
"updated_at": "2018-04-13 12:37:52",
"deleted_at": null,
"client_id": 1,
"hotel_id": 1
},
{
"id": 1,
"roomtype_id": 1,
"room_count": null,
"max_adult": 2,
"max_children": 1,
"capacity": 3,
"room_number": null,
"floor": null,
"number": null,
"name": null,
"city_name": "Abiramam",
"city": 3551,
"price": "435.00",
"extra_bed_price": null,
"astatus": "1",
"status": "0",
"created_at": "2018-04-13 10:33:24",
"updated_at": "2018-04-13 11:21:38",
"deleted_at": null,
"client_id": 1,
"hotel_id": 1
}
]
}
},
{
"id": 4,
"hotel_id": 2,
"deal_code": "ertgerf",
"date": "2018-04-13 00:00:00",
"discount": 1,
"status": 1,
"created_at": "2018-04-13 11:47:39",
"updated_at": "2018-04-13 11:53:45",
"deleted_at": null,
"client_id": 2,
"hotel": {
"id": 2,
"name": "Temperance Lane",
"address": "Temperance Ln, Sydney NSW 2000, Australia",
"phone": "9842814927",
"country": "14",
"country_name": "Austria",
"state": "281",
"state_name": "Carinthia",
"city": "6843",
"city_name": "Maria Rain",
"area": "test",
"pincode": "2000",
"nearest_airport": "demo",
"nearest_railway": "test",
"star": null,
"check_in": "09:30 AM",
"check_out": "04:30 PM",
"lat": "-33.86963590000001",
"lng": "151.20667979999996",
"description": "test description",
"astatus": "1",
"status": "0",
"created_at": "2018-04-13 10:43:16",
"updated_at": "2018-04-13 11:41:25",
"client_id": 2,
"hotel_age": null,
"hotel_privilege": "testtesttesttesttesttesttesttesttesttesttest",
"departure": "testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttest",
"checkout_fee": "testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttest",
"book_policy": "testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttest",
"hotel_secured": null,
"hotel_pets": null,
"hotel_other": "testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttest",
"room": [
{
"id": 2,
"roomtype_id": 1,
"room_count": null,
"max_adult": 2,
"max_children": 3,
"capacity": 5,
"room_number": null,
"floor": null,
"number": null,
"name": null,
"city_name": "Maria Rain",
"city": 6843,
"price": "345.00",
"extra_bed_price": null,
"astatus": "1",
"status": "0",
"created_at": "2018-04-13 10:46:04",
"updated_at": "2018-04-13 10:47:05",
"deleted_at": null,
"client_id": 2,
"hotel_id": 2
}
]
}
}
]
This sorts the rooms of each hotel per price:
$greatDealsinitial->each(function($deal) {
$deal->hotel->setRelation('room', $deal->hotel->room->sortBy('price'));
});
$greatDeals = $greatDealsinitial->hotel->room->sortBy('price')
if this array looks
[
['price' => 0],
['price' => 1],
['price' => 3]
]

How to filter laravel collection from given data

i have a collection data
{
"success": true,
"doctor": [
{
"id": 1,
"name": "Dr. Mayank",
"dob": "1975-01-01",
"about": "This is description",
"status": 1,
"rating": 2,
"rating_given_by": 1,
"alternative_number": "7686876876",
"profile_photo": [],
"speciality": [
{
"id": 3,
"name": "Acupuncture",
"image": null,
"dashboard_flag": 1
},
{
"id": 4,
"name": "Acupuncturist",
"image": null,
"dashboard_flag": 1
},
{
"id": 1,
"name": "Accident and emergency medicine",
"image": "http://192.168.16.21/remidify/media/174/detail.png",
"dashboard_flag": 1
}
],
"service": [
{
"id": 78,
"name": "Correction of gummy smile",
"cost": "12.00"
},
{
"id": 77,
"name": "Dental aesthetics",
"cost": "43.00"
}
],
"clinics": [
{
"id": 1,
"name": "akram",
"entity_id": 1,
"entity_type": "App\Doctor",
"contact_number": "2132132132132",
"status": 0,
"consultancy_fee": "12.00",
"available_today": "No",
"owner_name": "Dr. Mayank",
"pivot": {
"doctor_id": 1,
"clinic_id": 1
},
"address": {
"id": 1,
"address_1": "asdasdasdsa",
"address_2": "",
"locality": "downtown",
"city": "noida",
"state": "up",
"postal_code": "41561566"
},
"speciality": [],
"service": [
{
"id": 11,
"name": "Laminates",
"cost": "20.00"
},
{
"id": 12,
"name": "Dental surgery",
"cost": "300.00"
}
],
"clinic_image": [
{
"id": 7,
"model_id": 1,
"model_type": "App\Clinic",
"collection_name": "clinic_image",
"file_name": "1494863957588.566162.jpg",
"disk": "media",
"url": "http://192.168.16.21/remidify/media/7/1494863957588.566162.jpg"
}
],
"id_image": [
{
"id": 8,
"model_id": 1,
"model_type": "App\Clinic",
"collection_name": "id_image",
"file_name": "1494863966218.348877.jpg",
"disk": "media",
"url": "http://192.168.16.21/remidify/media/8/1494863966218.348877.jpg"
}
],
"location": {
"id": 1,
"latitude": 0,
"longitude": 0,
"entity_id": 1,
"entity_type": "App\Clinic",
"created_at": "2017-05-16 03:00:10",
"updated_at": "2017-05-16 03:00:10"
},
"clinic_timings": [
{
"day": "sun",
"opens_at": "09:28:00",
"closes_at": "21:28:00"
}
]
}
],
"education": [
{
"id": 19,
"degree": "MBBS",
"university": "Univercity",
"year": "2017",
"entity_id": 1,
"entity_type": "App\Doctor",
"created_at": "2017-05-16 05:44:11",
"updated_at": "2017-05-16 05:44:11",
"location": "Delhi"
}
],
"experience": [
{
"id": 19,
"hospital": "Hospital name",
"post": "pta ni hai",
"from": "1970-01-01",
"to": "0000-00-00",
"entity_id": 1,
"entity_type": "App\Doctor",
"created_at": "2017-05-16 05:44:12",
"updated_at": "2017-05-16 05:44:12",
"location": "Locations12",
"is_currently_working": 1
}
],
"registration": {
"id": 1,
"registration_number": "Reg # 2324324",
"registration_year": 1975,
"registration_council": "Council",
"experience": null,
"doctor_id": 1,
"created_at": "2017-05-16 02:56:37",
"updated_at": "2017-05-16 02:56:37",
"adhaar_number": "232131231232",
"id_proof": [
{
"id": 2,
"model_id": 1,
"model_type": "App\DoctorRegistration",
"collection_name": "id_proof",
"file_name": "1494863680447.329102.jpg",
"disk": "media",
"url": "http://192.168.16.21/remidify/media/2/1494863680447.329102.jpg"
}
],
"registration_proof": [
{
"id": 3,
"model_id": 1,
"model_type": "App\DoctorRegistration",
"collection_name": "registration_proof",
"file_name": "1494863687436.266846.jpg",
"disk": "media",
"url": "http://192.168.16.21/remidify/media/3/1494863687436.266846.jpg"
}
],
"qualification_proof": [
{
"id": 4,
"model_id": 1,
"model_type": "App\DoctorRegistration",
"collection_name": "qualification_proof",
"file_name": "1494863695576.803955.jpg",
"disk": "media",
"url": "http://192.168.16.21/remidify/media/4/1494863695576.803955.jpg"
}
]
},
"preference": {
"availability": 1,
"appointment_confirmation_method": "manual",
"average_time": 7,
"holiday_from": null,
"holiday_till": null,
"patients_per_hour": null,
"preferred_appointment_type": "timeslot",
"appointment_frequency": null,
"preferred_payment_method": [
{
"payment_method": "cash"
},
{
"payment_method": "online"
}
]
},
"user": null,
"doctor_clinic": [
{
"doctor_id": 1,
"clinic_id": 1,
"consultancy_fee": "12.00",
"deleted_at": null,
"workdays": [
{
"day": "sun",
"available": 1,
"workhours": [
{
"from": "09:28:00",
"to": "21:28:00"
}
]
}
],
"service": []
}
]
}
]
}
Now how can i find the doctors whose "about or specialty name" matches with some given search string.
Thanks in advance.
Try using dd() helper and use like this below
$youcollectionvariables = { "success": true, "doctor": [ { "id": 1, "name": "Dr. Mayank", "dob": "1975-01-01"................. }
dd($youcollectionvariables)
you will see a formatted data and can find what you need clearly.
Hope that helps.

Resources