farshadf

farshadf

Member Since 5 Months Ago

Experience Points 1,810
Experience Level 1

3,190 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed 5
Lessons
Completed
Best Reply Awards 0
Best Reply
Awards
  • start-engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist Created with Sketch.

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

14 Sep
2 days ago

farshadf started a new conversation How To Receive Data From User With Request With Less Code In Laravel

i want to recive 10 variables from my front side for example so what i do i have to write like below :

        $item1 = $request->get('item1');
        $item2 = $request->get('item2');
        $item3 = $request->get('item3');
        $item4 = $request->get('item4');
        $item5 = $request->get('item5');
        $item6 = $request->get('item6');

i want to know if there is any way to write it in 1 line of code as it makes my code so messy , or any other optimized or better way to get the variables from user with less code

11 Sep
5 days ago

farshadf left a reply on How To Get Properies Of A Relationship As Comma Separated Values In Laravel?

Ok thanks thats just what i want for now !!! You are Right Because in future if i want to show the gallery relationship fully on some other Api i guess i cant do it . i am fairly fimilar with resources but they are a pain when it comes to working with collections and when u want to do some similar thing that u did in model with resource i guess it would be like 100 times harder :) thanks man u r a life saver :)

farshadf left a reply on How To Get Properies Of A Relationship As Comma Separated Values In Laravel?

1 more thing is that it also loads the whole relationship under the model which i dont want it how can i make the model not to show the whole relation as a nested object ?? i wanted to shorten my api but some how now its duplicated once i have all comma seperated and then i have then as an object under my home !!!

farshadf left a reply on How To Get Properies Of A Relationship As Comma Separated Values In Laravel?

lol yes i changed that to facilities and now its working :) it is the same for all kind of relationships ? and can i append more than 1 field to a model ?? and one more question is that naming for $append laravel standards or its for php ??? and btw thanks for the answer that was really wise and it helped me

farshadf left a reply on How To Get Properies Of A Relationship As Comma Separated Values In Laravel?

    "message": "Call to a member function pluck() on null",

i get this error and when i dd $this->facility its null

farshadf left a reply on How To Get Properies Of A Relationship As Comma Separated Values In Laravel?

How can i use that in my $data now ?? because i want to to be there as a nested object

farshadf started a new conversation How To Get Properies Of A Relationship As Comma Separated Values In Laravel?

I have a ManyToMany relationship for example Facility and Home so here is the example of the relationship:


public function facility()
{
    return $this->belongsToMany(facility::class)->withPivot('is_free');
}
and in facility I have:

public function home()
{
   return $this->belongsToMany(Home::class)->withPivot('is_free');
}

and in some controller I do like below :


$data = Home::with('facility')->get;

it gives me the result like below :



{
    name: example,
    id: 1,
    facility: {
        id: 1,
        name:item1,
    },
    {
        id: 1,
        name:item1,
    },
    {
        id: 1,
        name:something,
    }
}

now i want it comma separated like below :


{   
    name:example,
    id : 1,
    some other fileds ,
    ,
    , 
         facility: {item1,item2,item3,item4,. . .
    }
}

so I want them comma separated and only pick some certain columns from it

04 Sep
1 week ago

farshadf started a new conversation How To Customize Api With Resource On Collection

i have a collection on my controller as below :


 $data = Accommodation::with(['city','accommodationRoomsLimited.roomPricingHistorySearch' =>function($query) use($from_date,$to_date){
                $query->whereDate('from_date', '<=', $from_date);
                $query->whereDate('to_date', '>=', $to_date);
                }])    
                ->get();
            return new FilterResource($data);

and here is my filter resource


  public function toArray($request)
    {
//        return parent::toArray($request);
        return [
            'id' => $this->id,
    'costumfields' => 'somecostumfields'
        ];
    }

now i want to customize my resource so that i can add some custom fields to it and customize the current fields on the api but this code gives me the error below :


"message": "Property [id] does not exist on this collection instance.",
10 Aug
1 month ago

farshadf started a new conversation Laravel Show Unit Test Is Not Asserting.

i have a laravel application that i want to write tests for now when i run show test its not working and i am writing this test for my api btw : so my test is like below :


public function testShow()
{
    $response = $this->json('GET', '/api/roomfacility/{roomfacility}', []);

    $response->assertStatus(200);

}

but i get this error :



    20) Tests\Feature\RoomCapacityHistoryTest::testShow
Expected status code 200 but received 404.
Failed asserting that false is true.

i want to know what is the error here because when i try it in browser it works and i want to know how to test my crud api , i want to test my index,show,create,update for my api i know there are some tutorials about the testing but they are not about the api .

05 Aug
1 month ago

farshadf left a reply on Reciving The Send Data From Laravel To Logstash In Kibana

Yes i saw nothing in that i dont know which one is any guide on how to connect kibana to logstash

farshadf started a new conversation Reciving The Send Data From Laravel To Logstash In Kibana

i am using laravel to send my logs to logstash and i want to show them in kibana now here is what i did : in logging.php


   'logstash' => [
        'driver' => 'custom',
        'via'    => \App\LogstashLogger::class,
        'host'   => env('LOGSTASH_HOST', '127.0.0.1'),
        'port'   => env('LOGSTASH_PORT', 9200),
    ],

and here is the logstashlogger class :


    <?php
/**
 * Created by PhpStorm.
 * User: farshad
 * Date: 8/5/19
 * Time: 1:19 PM
 */

namespace App;

use Monolog\Formatter\LogstashFormatter;
use Monolog\Handler\SocketHandler;
use Monolog\Logger;
use Psr\Log\LoggerInterface;
class LogstashLogger {
    /**
     * @param array $config
     * @return LoggerInterface
     */
    public function __invoke(array $config): LoggerInterface
    {
        $handler = new SocketHandler("udp://{$config['host']}:{$config['port']}");
        $handler->setFormatter(new LogstashFormatter(config('app.name')));
        return new Logger('logstash.main', [$handler]);
    }
}

so in tinker when i run this command :


>>> Log::channel('logstash')->info('Hello logstash!');

i get the null back without any error in log that it should mean that data is send to logstash successfully , so now how can i get the datafrom logstash and show them in kibana because when i want to m Create index pattern it wont accept any name and i dont know how to check if i recived the data in logstash or no . or how to show them in kibana !!!

04 Aug
1 month ago

farshadf started a new conversation Laravel Log System With Logstash

i have a laravel application that i want to store my logs into my logstash and see them in kibana i searched a lot over the net to find a solution for it but i didnt find any good source for it, is there any package to use laravel logs into logstash ??? by the way i have my logstash and kibana running without any problem i just need a source of data now . and here is my elstic search running :

    {
name: "5351ced3b7a4",
cluster_name: "elasticsearch",
cluster_uuid: "Ej5TRN8CQyGvemZlT3gAFA",
version: {
number: "7.1.1",
build_flavor: "oss",
build_type: "tar",
build_hash: "7a013de",
build_date: "2019-05-23T14:04:00.380842Z",
build_snapshot: false,
lucene_version: "8.0.0",
minimum_wire_compatibility_version: "6.8.0",
minimum_index_compatibility_version: "6.0.0-beta1"
},
tagline: "You Know, for Search"
}
28 Jul
1 month ago

farshadf started a new conversation Adding Log System To Laravel

Hi i want to make a complete log for my laravel system that records every thing that user does or where ever the user goes now i am using spatie activity log on my system i want to know if there is any possibility or tutorial about elastic cause i heard that its the best practice to save the logs on it specially if its to much of data . thanks for your help

16 Jul
2 months ago

farshadf started a new conversation Handle Query Strings In Laravel And How Secure Are They

i want to know how secure is it to handle post requests with Query strings and if its not secure how can i disable the user to send any query string to my api cause right now the user is able to send any query string regardless of its being right query string or wrong one and in the end can $request get the data from body(From Post man app sending )

farshadf started a new conversation How To Manage Laravel Big Update Methods

i have an update method like below which is so big and i want to manage it some how that in take less place in controller and make controller much cleaner now i want to know if there is any way to make it as service or some thing this is my update method for example :


      public function update(Request $request, Something $something)
    {
  
        $something->somefield = $request->get('field1');
        $something->somefield = $request->get('field1');
        $something->somefield = $request->get('field1');
        $something->somefield = $request->get('field1');
        $something->somefield = $request->get('field1');
        $something->save();
        return response()->json($something, 200);
  //consider i may have like 20 fields here

farshadf left a reply on How To Implement Repository Pattern In Laravel

i meant the laravel but ofc pattern is same :)

farshadf left a reply on How To Implement Repository Pattern In Laravel

Oh i should have missed that course . but isnt that outdated and so old because its for 2013 ?? and thanks for answer

farshadf started a new conversation How To Implement Repository Pattern In Laravel

Although there Are some Tutorials on medium and some other sites about the Repository pattern for laravel i read in some sites that repository pattern will duplicate the ORM and You wont need it in laravel so now i have 2 questions : is it right to implement Repository pattern in laravel ?? if yes What is the best source of tutorial because laracast i think has no tutorial on that nether do any good source done any thing about it . and finally if not what is the best solution to make controller more beautiful and short

farshadf left a reply on How To Seperate Requests From Controller For Making Code Cleaner

Then If my Front sends the variable in wrong order it would save it in a wrong variable so i think this cant be very good as i see .

farshadf started a new conversation How To Seperate Requests From Controller For Making Code Cleaner

hi , in some cases in my controller i have to recive like 12 params from my client side and i have to like below for each of variables :

        $something = $request->get('something');

i want to know if there is any way to seperate this code form my controller and recive them in my controller and use them in my method so my code will become cleaner and more readble .

03 Jun
3 months ago

farshadf left a reply on Laravel 5 Manage Big Controllers In Projects

@SNAPEY - thanks thats going to help !!!

02 Jun
3 months ago

farshadf started a new conversation Laravel 5 Manage Big Controllers In Projects

0

i have a controller that can contain up to 2k line of code and so many costum methods now i want to make this controller more readable and better so i read somewhere i its a best pratice just to use main methos in my controller like below :


    public function index(){
.
.
.
}
  public function store(){
.
.
.

    }

now my question is that if i keep these main functions on controller what should i do to other methods and where to store them to make them more readable and make more space for future methods

29 May
3 months ago

farshadf left a reply on How To Make Laravel Swagger Automaticly Detects Annotation

@DEVFREY - right but how is that some frameworks like .netcore handling that and swagger detects all thing automaticly

farshadf started a new conversation How To Make Laravel Swagger Automaticly Detects Annotation

i want to use swagger on my laravel api but i dont want to make annotation for every single one of my controller and api there are some packages on the net like DarkOline and some other but i think they dont have the auto detection like the .netcore which automaticly recognize all parameters in controller and make swagger for them !! so my point is i dont want this annotation like below that i write :


    /**
 * @SWG\Get(
 *      path="/get-accommodation-facilities",
 *      operationId="getAccommodationFacilityList",
 *      tags={"AccommodationFacilityById"},
 *      summary="Get list of accommodation facility By Id",
 *      description="Returns list of accommodationFacility by thier accommodation Id",
 *      operationId="findaccommodationfacilityByIdTags",
 * @SWG\Response(
 *     response=200,
 *     description="Success",
 *     @SWG\Schema(
 *             title="AccommodationFacility",
 *          @SWG\Property(type="integer", property="accommodation_facility_type_id", description="accommodation_facility_type_id"),
 *          @SWG\Property(type="string", property="name", description="name"),
 *          @SWG\Property(type="string", property="english_name", description="english_name"),
 *          @SWG\Property(type="integer", property="is_deleted", description="is_deleted"),
 *     )
 * ),
 *       @SWG\Response(response=404, description="Not Found"),
 *       security={
 *           {"api_key_security_example": {}}
 *       }
 *
 *     )
 *
 * Returns list of accommodations
 */

i have like 100 apis so i cant do it for each single on of them as they some accept some nested

20 May
3 months ago

farshadf started a new conversation Laravel Swagger Auto Generator Documenter

i need a package to document my api with swagger i know there is a api documented package but i want exactly swagger i find a package for swagger but it requires to write a lot of custom code to recognize fields of api and document it so like .netcore i want to know if there is any way to auto generate documentation for my api in swagger in laravel

farshadf left a reply on How To Show Array As Separated Fields In Laravel Resource Api

Omg i Cant stop My Tears it worked i really dont know how but its working thanks my friend i really dont know how to thank you i had no idea how to this and i deadly needed that thanks thanks

farshadf started a new conversation How To Show Array As Separated Fields In Laravel Resource Api

I have a resource that I am sending 2 additional data to it which are 2 arrays like below : This is my resource :


   /**
 * @var
 */
private $foo;

/**
 * Create a new resource instance.
 *
 * @param  mixed  $resource
 * @return void
 */
public function __construct($resource, $hasroom,$hasdate)
{
    // Ensure you call the parent constructor
    parent::__construct($resource);
    $this->resource = $resource;
        $this->hasroom = $hasroom;
        $this->hasdate = $hasdate;

}
/**
 * Transform the resource into an array.
 *
 * @param  \Illuminate\Http\Request  $request
 * @return array
 */
public function toArray($request)
{            return [
            'hasroom' => $this->hasroom,
            'hasdate' => $this->hasdate,
        ];
    }
}

and here is where I send addinitonal data from controller :

return new BookingStatusResource($dates, $hasroom,$hasdate); and here what i get as output :


{
data: {
hasroom: [
1,
2,
3,
4,
5
],
hasdate: [
"2019-03-31T19:30:00.000000Z",
"2019-03-31T19:30:00.000000Z",
"2019-04-01T19:30:00.000000Z",
"2019-04-01T19:30:00.000000Z",
"2019-04-02T19:30:00.000000Z",
]
}
}

but here is the format that I want to receive from the output :


    {
data: {
{
  'hasroom':1,
  'hasdate':"2019-03-31T19:30:00.000000Z"
},
{
  'hasroom':2,
  'hasdate':"2019-03-31T19:30:00.000000Z"
},


}

I want know how to merge those 2 arrays and show them next to each other in my resource.

12 Apr
5 months ago

farshadf left a reply on How To Use Queries On 2 Relationships In Laravel

@CRONIX - i am afraid not cronix because i do this like below but the result is i get all the properties no matter the where queries !!!

 $data = Property::with(['dates' => function ($query) {
          $query->where('date', 'like', '4/11/2019'); 
       }],['details' => function ($query) {
          $query->where('city', 'like', 'london');
      }])->get();
        dd($data);
11 Apr
5 months ago

farshadf started a new conversation How To Use Queries On 2 Relationships In Laravel

i have a model and 2 relationships i want to do a where on each relationship so for example show me a room that date is 4/11/2019 and the city in london : here is my code : my controller :


        $test = Property::with('dates','details')->get();

and here is a dd of my $test and sorry it may be a bit long but i expand all for you to see the relations because dates is a pivot relation :



    Collection {#1708 ▼
 

     #items: array:2 [▼
        0 => Property {#1457 ▼
          #guarded: []
          #connection: "mysql"
          #table: "properties"
          #primaryKey: "id"
          #keyType: "int"
          +incrementing: true
          #with: []
          #withCount: []
          #perPage: 15
          +exists: true
          +wasRecentlyCreated: false
          #attributes: array:8 [▶]
          #original: array:8 [▶]
          #changes: []
          #casts: []
          #dates: []
          #dateFormat: null
          #appends: []
          #dispatchesEvents: []
          #observables: []
          #relations: array:2 [▼
            "dates" => Collection {#1607 ▼
              #items: array:1 [▼
                0 => Date {#1600 ▼
                  #connection: "mysql"
                  #table: "dates"
                  #primaryKey: "id"
                  #keyType: "int"
                  +incrementing: true
                  #with: []
                  #withCount: []
                  #perPage: 15
                  +exists: true
                  +wasRecentlyCreated: false
                  #attributes: array:7 [▶]
                  #original: array:9 [▶]
                  #changes: []
                  #casts: []
                  #dates: []
                  #dateFormat: null
                  #appends: []
                  #dispatchesEvents: []
                  #observables: []
                  #relations: array:1 [▼
                    "pivot" => Pivot {#1602 ▼
                      +incrementing: false
                      #guarded: []
                      #connection: null
                      #table: "date_property"
                      #primaryKey: "id"
                      #keyType: "int"
                      #with: []
                      #withCount: []
                      #perPage: 15
                      +exists: true
                      +wasRecentlyCreated: false
                      #attributes: array:2 [▶]
                      #original: array:2 [▶]
                      #changes: []
                      #casts: []
                      #dates: []
                      #dateFormat: null
                      #appends: []
                      #dispatchesEvents: []
                      #observables: []
                      #relations: []
                      #touches: []
                      +timestamps: false
                      #hidden: []
                      #visible: []
                      #fillable: []
                      +pivotParent: Property {#1461 ▶}
                      #foreignKey: "property_id"
                      #relatedKey: "date_id"
                    }
                  ]
                  #touches: []
                  +timestamps: true
                  #hidden: []
                  #visible: []
                  #fillable: []
                  #guarded: array:1 [▶]
                }
              ]
            }
            "details" => PropertyDetail {#1702 ▼
              #fillable: array:7 [▶]
              #connection: "mysql"
              #table: "property_details"
              #primaryKey: "id"
              #keyType: "int"
              +incrementing: true
              #with: []
              #withCount: []
              #perPage: 15
              +exists: true
              +wasRecentlyCreated: false
              #attributes: array:10 [▶]
              #original: array:10 [▼
                "id" => 52
                "property_id" => 65
                "state" => "london"
                "city" => "london"
                "address" => "5"
                "post_code" => 5
                "placearea" => 1
                "telephone" => 5
                "created_at" => "2019-04-09 21:03:10"
                "updated_at" => "2019-04-09 21:03:10"
              ]
              #changes: []
              #casts: []
              #dates: []
              #dateFormat: null
              #appends: []
              #dispatchesEvents: []
              #observables: []
              #relations: []
              #touches: []
              +timestamps: true
              #hidden: []
              #visible: []
              #guarded: array:1 [▶]
            }
          ]
          #touches: []
          +timestamps: true
          #hidden: []
          #visible: []
          #fillable: []
        }
        1 => Property {#1458 ▶}
      ]
    }

farshadf left a reply on Is There Anything In Laravel Natively That Can Give Ajax Like Functionality?

@shamrat1 i am not sure if i got you right or no but laravel ships with vuejs and vue uses axios to make spa s and ajax requests so have you cheked that out ??

02 Apr
5 months ago

farshadf left a reply on Make A Search Form And Show Result On The Same Page

@SNAPEY - oh Ok i tried and saw that just now thank you i always had problem with it to retrieve in front now its much easier thanks snapey

farshadf started a new conversation Laravel 5 - How To Sort And Search A Collection Instance

i have a many to many pivot relation between 2 model of property and date that a user can see if the room is available for reserve or not every thing is working fine until i want to search the available date so my user submit 2 dates and i want to sort all dates related to that room and just show the days between that 2 user input so i know and tried dateBettwen but because i use pivot table i must some how do this on sort and search collection instance i guess so here is a part of my code : this is my collection dd if its possible to sort and do operation on it :


Collection {#1606 ▼


 #items: array:1 [▼
    0 => Property {#1441 ▼
      #connection: "mysql"
      #table: "properties"
      #primaryKey: "id"
      #keyType: "int"
      +incrementing: true
      #with: []
      #withCount: []
      #perPage: 15
      +exists: true
      +wasRecentlyCreated: false
      #attributes: array:14 [▶]
      #original: array:14 [▶]
      #changes: []
      #casts: []
      #dates: []
      #dateFormat: null
      #appends: []
      #dispatchesEvents: []
      #observables: []
      #relations: array:1 [▼
        "dates" => Collection {#1605 ▼
          #items: array:5 [▼
            0 => Date {#1586 ▼
              #connection: "mysql"
              #table: "dates"
              #primaryKey: "id"
              #keyType: "int"
              +incrementing: true
              #with: []
              #withCount: []
              #perPage: 15
              +exists: true
              +wasRecentlyCreated: false
              #attributes: array:5 [▼
                "id" => 1
                "date" => "2019-03-31 00:00:00"
                "price" => 21000.0
                "created_at" => "2019-03-31 00:00:00"
                "updated_at" => null
              ]
              #original: array:7 [▶]
              #changes: []
              #casts: []
              #dates: []
              #dateFormat: null
              #appends: []
              #dispatchesEvents: []
              #observables: []
              #relations: array:1 [▶]
              #touches: []
              +timestamps: true
              #hidden: []
              #visible: []
              #fillable: []
              #guarded: array:1 [▶]
            }
            1 => Date {#1587 ▶}
            2 => Date {#1588 ▶}
            3 => Date {#1589 ▶}
            4 => Date {#1590 ▶}
          ]
        }
      ]
      #touches: []
      +timestamps: true
      #hidden: []
      #visible: []
      #fillable: []
      #guarded: array:1 [▶]
    }
  ]```

and here is my controller :

if (!empty($request->start_date)) {

$pdate = Property::with('dates')
    ->get();
  here on pdate i wana do some sorting and searching base on user send start and end date
    dd($pdate);
}```

date table here :


Schema::create('dates', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->dateTime('date');
            $table->float('price');
            $table->timestamps();
        });

and property table :


 public function up()
{
    Schema::create('properties', function (Blueprint $table) {
        $table->bigIncrements('id');
        $table->integer('type');
        $table->text('title');
        $table->longText('description');
        $table->longText('image');
        $table->float('base_price');
        $table->dateTime('available_start');
        $table->dateTime('available_end');
        $table->integer('base_availability');
        $table->integer('base_capacity');
        $table->integer('max_occupancy');
        $table->float('extra_price');
        $table->timestamps();
    });

and the pivot table :



Schema::create('date_property', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->integer('property_id');
            $table->foreign('property_id')->references('id')->on('property');
            $table->integer('date_id');
            $table->foreign('date_id')->references('id')->on('date');
            $table->integer('reserved');
            $table->timestamps();
        });

farshadf left a reply on Make A Search Form And Show Result On The Same Page

@SNAPEY - yes i have defined that here is the code :


 public function dates(){
        return $this->belongsToMany(Date::class);
    }

so u mean i can achive that with something like this ??

$property->dates ;

and it would give me all pivots related to that property ?? i got a bit confused

farshadf left a reply on Many To Many Problem

how you transform data can you show it ?? or the method you using ??

farshadf left a reply on Make A Search Form And Show Result On The Same Page

@snapey you mentioned good point because that was another question of mine well some parts you mentioned i just placed them to see the workflow and when it works i edit the queries but lets see some parts here now :

 $property->load('propertycalendars');
      foreach ($property->propertycalendars as $prop) {
           $end_reserve = $prop->reserve_end;
       }

it was for a previous method of my work that was my bad not to remove them i am sorry about that :) the important part is here :

$pdate = Property::with('dates')->get();

here is a short story of it i have property and date model and a many to many relation with a pivot table this dates is the relation name of it , so i wana get all the dates that this room(property) has !!! is that code wrong ? or not optimized ??

01 Apr
5 months ago

farshadf started a new conversation Make A Search Form And Show Result On The Same Page

i want to make a search form that searches some dates and show the result to user on the same page that search submits which is this case is the show method of laravel which makes the job double hard i think so considering that i am on show method here is some part of my code

     public function show(Property $property)
    {

        $property = Property::with('propertycalendars')->where('id', $property->id)->first();
        foreach ($property->propertycalendars as $prop) {
            $end_reserve = $prop->reserve_end;
        }
//             HERE NEW RELATION
        $pdate = Property::with('dates')->get();

        return view('users.properties.show', compact('property','pdate','end_reserve'));
    }
//    search dates
     public function search (Request $request,Property $property){
    //Send an empty variable to the view, unless the if logic below changes, then it'll send a proper variable to the view.
    $results = null;

    //Runs only if the search has something in it.
    if (!empty($request->property_id)) {
        $start_date = $request->start_date;
        $search_date = Date::all()->where('date',$start_date);
    }
    $pdate = Property::with('dates')->get();
    return view('users.properties.show',compact('search_date','property','pdate'));
}

and here is my route :


Route::resource('/properties','PropertyController');
Route::post('/properties/search','[email protected]');

and finally the form that i use :


 <form action="/properties/search" method="post">
                {{csrf_field()}}

                <div class="row">
                <div class="col-lg-5">
                    <input type="hidden" value="{{$property->id}}" name="property_id">
                    <input name="start_date"  class="form-control m-input start_date" autocomplete="off"></div>

                <div class="col-lg-5">
                    <input name="title"  class="form-control m-input end_date" autocomplete="off"></div>

                <div class="col-lg-2">
                    <input type="submit" value="search" class="btn btn-primary btn-block" autocomplete="off">
                </div>
            </div>
            </form>

so with this code now i get the blank page with nothing inside but i want to show the old property.show page just + to search result . i would be happy to get any kind help if possible ty :)

28 Mar
5 months ago

farshadf started a new conversation Sum And Mines Calculator In Vue.js

i want to make a sort of calculator for a service so a certain number costs certain amount and if the users changes the numbers the cost changes to increase to user increase and decrease by user decreasing number , for this i am using a minus plus input for vuejs from git hub and here is the code i use


        methods:{
            getNotificationClass (notification) {
                return `alert alert-${notification.type}`
            },
            mpminus: function () {
                if ((this.newValue) > this.min) {
                    this.newValue = this.newValue - 1
                    this.$emit('input', this.newValue)
                }

            },
            mpplus: function () {
                if (this.max === undefined || (this.newValue < this.max)) {
                    this.newValue = this.newValue + 1
                    this.$emit('input', this.newValue)
                }
                if(this.newValue > this.base_capacity){
                    this.totalprice =  this.extra_price * 2
                    alert('dead')
                    this.$emit('input', this.totalprice)
                } else {

                }
            },


        },

and here are the props and the data


 export default {
        props: {
            reserve_end:{

            },
            available_end:{

            },
            extra_price:{
                type: Number,
                required: true
            },
            total_price:{
              type:Number
            },
            max_occupancy: {
                type : Number,
                required: true
            },
            base_capacity: {
                type: Number,
                required: true
            },
            base_price: {
                type: Number,
                required: true
            },

            value: {
                default: 0,
                type: Number
            },
            min: {
                default:5,
            type:Number
            },
            max: {
                default: 22,
                type: Number
            },
        },
        data(){
            return {
                date: '',
                date2:'',
                newValue: 5,
                totalprice:1,
            }
        },

and here finally the template

<div class="minusplusnumber">
                            <div class="mpbtn minus"  v-on:click="mpminus()">
                                -
                            </div>
                            <div id="field_container">
                                <input type="number" v-model="newValue" disabled />
                            </div>
                            <div class="mpbtn plus"  v-on:click="mpplus()">
                                +
                            </div>
                            <input type="number" v-model="totalprice" disabled />

                        </div>

here for example i wrote an if and its working but just once i mean if the user passes the base capacity it doubles the amount and then nothing but i want to make it double every single time user increases the number i hope i was clear enough of what i wanna do

25 Mar
5 months ago

farshadf left a reply on Making A Reservation App Analyse Question

@JLRDW - thanks for the help i will keep more searching about it but i got the hint from you thanks :)

farshadf left a reply on Making A Reservation App Analyse Question

@JLRDW - thanks there is a good toturial it seems on codetutorial.io but the site is down :(

farshadf started a new conversation Making A Reservation App Analyse Question

i want to make a reservation application with laravel that for example i reserve a room in hotel for a certain date to another and the other point is that to check if the room is available for each day or to say better to check if the provider (hotel) provides the room for certain days or no if its not available so it cant be reserved . any idea how to handle this ?? i am 100% sure that this is wrong but i was thinking of making a table for 30 days and fill them with available status and reserved status !!!