ssquare

ssquare

Member Since 1 Year Ago

Experience Points
3,270
Total
Experience

1,730 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.

Level 1
3,270 XP
Oct
20
2 days ago
Activity icon

Started a new Conversation Connection Time Out For Smtp Checks

I am trying to check if the entered SMTP details are correct or not.

So, I run the following code:

use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;

        //Create a new SMTP instance
        $smtp = new SMTP;
//Enable connection-level debug output
        $smtp->do_debug = SMTP::DEBUG_CONNECTION;
        try {
            //Connect to an SMTP server
            if (!$smtp->connect('host.example.com', port_number)) {
                throw new Exception('Connect failed');
            }
            //Say hello
            if (!$smtp->hello(gethostname())) {
                throw new Exception('EHLO failed: ' . $smtp->getError()['error']);
            }
            //Get the list of ESMTP services the server offers
            $e = $smtp->getServerExtList();
            //If server can do TLS encryption, use it
            if (is_array($e) && array_key_exists('STARTTLS', $e)) {
                $tlsok = $smtp->startTLS();
                if (!$tlsok) {
                    throw new Exception('Failed to start encryption: ' . $smtp->getError()['error']);
                }
                //Repeat EHLO after STARTTLS
                if (!$smtp->hello(gethostname())) {
                    throw new Exception('EHLO (2) failed: ' . $smtp->getError()['error']);
                }
                //Get new capabilities list, which will usually now include AUTH if it didn't before
                $e = $smtp->getServerExtList();
            }
            //If server supports authentication, do it (even if no encryption)
            if (is_array($e) && array_key_exists('AUTH', $e)) {
                if ($smtp->authenticate('[email protected]', 'secret_password')) {
                    echo 'Connected ok!';
                } else {
                    throw new Exception('Authentication failed: ' . $smtp->getError()['error']);
                }
            }
        } catch (Exception $e) {
            echo 'SMTP error: ' . $e->getMessage(), "\n";
        }
//Whatever happened, close the connection.
        $smtp->quit();
        echo "end";
        exit();

This solution is referred from the github page, https://github.com/PHPMailer/PHPMailer/blob/master/examples/smtp_check.phps

I have set up sendgrid as default SMTP driver in the .env file. Is it creating the issue?

Result is like

2019-10-20 14:50:37 Connection: opening to example.secureserver.net:465, timeout=30, options=array()
2019-10-20 14:50:37 Connection: opened
{
    "message": "Maximum execution time of 120 seconds exceeded",
    "exception": "Symfony\Component\Debug\Exception\FatalErrorException",
    "file": "D:\wamp64\www\email-project\vendor\phpmailer\phpmailer\src\SMTP.php",
    "line": 1156,
......
......
......
......

What could be the issue?

Sep
22
1 month ago
Activity icon

Started a new Conversation Get Count And Average Value Of Related Models

$data= Category::with(['amenities.unitAmenities'])->get();

Above code works perfectly fine and returns all the related data from the unitAmenities models. In this model, there is one column named amenity_value.

Now, I want to get the count and average of this amenity_value column.

Relation: Category - amenities ( one to one ) amenities - unitAmenities (one to many)

Is there any way to get count and average of this column directly with respect to category. Or, there is no any other way and need to loop through the $data

Sep
21
1 month ago
Activity icon

Replied to Update Field According To Condition During Mass Update

@bobbybouwmann I have created a boot function as follows:

public static function boot()
{
    parent::boot();
    self::updating(function ($modal) {

        if($modal->value == $modal->changed_value){
            $status = 0;
        }else{
            $status = 1;
        }
        $modal->status = $status;
      //print_r($modal);
    });
}

However, this boot function is not getting called during following method: i.e mass update

Model::where(am_'id',$request->am_id)
                ->update(
                    [
                        'changed_value' => $request->value
                    ]
                );

Only getting called during

$modal = Modal::findOrFail($id);
$modal->changed_value = $request->value;
$modal->save();
Sep
20
1 month ago
Activity icon

Started a new Conversation Update Field According To Condition During Mass Update

I have a table structure like:

id    //primary_key
value
changed_value    //on update value column should not be updated instead changed value should be updated
status    // 0 - default, 1- updated
am_id  //foreign_key

Now, to mass update I am doing as follows:

Model::where('am_id',$request->am_id)
        ->where('value',$request->value)
        ->update([
                         'changed_value' => '$request->value',
                         'status' => 1
                ]);

However, we should not set status as 1 blindly, as there is one condition. It's if the value of value column is equal to the $request->value the status should be 0 instead.

#How this scenario could appear?

Initially, after inserting the first row looks like

+-----+-------+---------------+--------+-------+
| id  | value | changed_value | status | am_id |
+-----+-------+---------------+--------+-------+
|  1  | 20    | null          | 0      | 1     |  
+-----+-------+---------------+--------+-------+

After 1st update

+-----+-------+---------------+--------+-------+
| id  | value | changed_value | status | am_id |
+-----+-------+---------------+--------+-------+
|  1  | 20    | 40            | 1      | 1     |   // changed_value - 40 , status 1
+-----+-------+---------------+--------+-------+

After 2nd Update (let's say the value is updated to 20), in this case as the value === changed_value the status should be updated as 0 not 1

+-----+-------+---------------+--------+-------+
| id  | value | changed_value | status | am_id |
+-----+-------+---------------+--------+-------+
|  1  | 20    | 20            | 0      | 1     |     // changed_value - 20 , status 0
+-----+-------+---------------+--------+-------+

This means, during the model update in below-mentioned code. I want to insert a condition, if( value == $request->value) status = 0 else status = 1

Model::where('am_id',$request->am_id)
        ->where('value',$request->value)
        ->update([
                         'changed_value' => '$request->value',
                         'status' => 1
                ]);
Sep
07
1 month ago
Activity icon

Replied to Form Is Not Being Posting To The Intended Route, What Should I Double Check

@tray2 I am using

    Route::match(['post', 'get'],'/', ['as' => 'amenityFront.index', 'uses' => '[email protected]']);

However, post method not sending any form data.

Activity icon

Replied to Form Is Not Being Posting To The Intended Route, What Should I Double Check

Yeah, I am doing the same only un-commenting during submit. And yeah, at that case I am receiving an empty array. Instead, if I choose to submit by GET method its working fine.

Activity icon

Replied to Form Is Not Being Posting To The Intended Route, What Should I Double Check

@nakov yeah I have commented that line. Is there any way how could I debug this? Check this route:list updated screenshot

https://ibb.co/JKQqvzT

Activity icon

Replied to Form Is Not Being Posting To The Intended Route, What Should I Double Check

@nakov

    public function index(Request $request)
    {
//        dd($request->all());
        $properties = Property::get(['id','property_name']);
        if($properties){
            $selectedProperty = $properties[0]->id;
        }else{
            $selectedProperty = new Property();
        }
        $query = Category::with(['amenities' => function($query) {
                                    $query->orderBy('amenity_name');
                                }])
                                ->orderBy('category_name');
        if($request->property){
            $query->where('property_id',$request->property);
            $selectedProperty = $request->property;
        }
        $categories = $query->get();

        return view('frontend.amenity.index',compact('properties','selectedProperty','categories'));
    }

I am also quite amazed why its not working, as it should have worked.

Also, check my form.

<form method="POST" action="{{route('amenityFront.index')}}" id="buildingByProperty">
                        <select class="form-control" name="property" id="propertySelect">
                            @foreach($properties as $pk => $pv)
                                <option value="{{$pv->id}}" {{ ($pv->id == $selectedProperty)?'selected':'' }}>{{$pv->property_name}}</option>
                            @endforeach
                        </select>
                    </form>
Activity icon

Replied to Form Is Not Being Posting To The Intended Route, What Should I Double Check

@Nokov okay, let me explain what I am doing. On the first view, if no data passed, it will show the output of default $id, however, if $id is passed it should show the same data of that particular id.

in programming I have done

if($request->param){ 
    //do one stuff
}else{
    do another Stuff
}

Okay, if I wanted to execute it on the same route with match as mentioned above:

    Route::match(['get', 'post'],'/', ['as' => 'amenityFront.index', 'uses' => '[email protected]']);

Form is not sending any data on the POST request, and would only send data on the GET request, what could be the reason?

Array
(
)

During POST request, it prints an empty array.

Activity icon

Replied to Form Is Not Being Posting To The Intended Route, What Should I Double Check

@nakov Instead my main intention was to use Route::match

 Route::match(['get', 'post'],'/', ['as' => 'amenityFront.index', 'uses' => '[email protected]']);

However, doing so it didn't send any data to the server I am testing it by separating to two routes and still no improvement.

I just need to send one additional data to the same route, as during first load there won't be any data and on this submit there will be some data being passed to the controller.

It is totally fine to send GET request as well on this submit as well. However, I don't want to show ?param1=abcd&param2=def in the url thats why I was trying to send the post request.

But, mainly I need to send the data to same url as it is performing the same action

Activity icon

Started a new Conversation Form Is Not Being Posting To The Intended Route, What Should I Double Check

I am trying to submit form to the laravel. Instead of postIndex it is still sending its request to @index.

My form looks like this:

<form method="POST" action="{{route('amenityFront.postIndex')}}" id="buildingByProperty">
    @csrf
    <select class="form-control" name="property" id="propertySelect">
        @foreach($properties as $pk => $pv)
            <option value="{{$pv->id}}" {{ ($pv->id == $selectedProperty)?'selected':'' }}>{{$pv->property_name}}</option>
        @endforeach
    </select>
    <button type="submit">Submit</button>
</form>

and route:

Route::get('/', ['as' => 'amenityFront.index', 'uses' => '[email protected]']);
    Route::post('/', ['as' => 'amenityFront.postIndex', 'uses' => '[email protected]']);

However, instead of redirecting to postIndex I am still being posted to @index

My route:list screenshot

https://ibb.co/LkJqQV8

Even more surprising, even on @index, if I try to print_r($request->all()) it display an empty array:

Array
(
)

By the way my controller:

public function postIndex(Request $request)
    {
        echo "zz";
        exit();
    }
Sep
06
1 month ago
Activity icon

Started a new Conversation Refactoring DB Select Sub Query

What is the best way to call the below mentioned DB:Select query. I don't want to use eloquent. How can I bind parameter in the subquery.

DB::select('SELECT * FROM   
      (  
       SELECT A.id as id,A.name,C.category_name 
       FROM alerts AS A 
       LEFT JOIN categories as C 
       ON A.category_id = C.id
       where A.id < '. $OldLowestID.'
       order by id asc  
       limit '.$pagesize.'
       ) as myAlias   
  ORDER BY id ASC');
Sep
05
1 month ago
Activity icon

Replied to Reverse Certain Job

@jirdw @mabdullahsari what about for job failed condition? Could I revert at that time? I have found some clue on https://laravel.com/docs/5.6/queues#job-events , however, I could not get how it should be done.

Sep
04
1 month ago
Activity icon

Started a new Conversation Reverse Certain Job

Is it possible to reverse a job if anything goes wrong during the execution process?

Let's say that I am inserting data from CSV, so during insertion instead of storing FirstName in first_name column, it was inserting in last_name column and vice versa. Now, I realized it is inserting the wrong data in wrong column. Now, could I roll back the work done by this particular job?

Is there any other thing to minimize the problems from these possible circumstances?

Aug
28
1 month ago
Activity icon

Replied to Make Combination Of Column Unique (not Working)

Sorry, my bad. I was adding separate unique for column1 as well. $table->integer('column1')->unique();

Activity icon

Started a new Conversation Make Combination Of Column Unique (not Working)

I am trying to make a combination of two columns unique not two separate unique columns.

I have done $table->unique( array('column1','column2') ); But, it looks like it have created each column need to be unique.

For this, I am not testing even with laravel. In my database, there is one row with

id | column1 | column2
1 | 110 | 1

But, when I try to insert new row from PHP my admin with column1 = 110 and column2 = 2 its throwing #1062 - Duplicate entry110for key table_column1_unique

For this, should I check duplicate only from request validation by removing unique from these two columns? I don't want to create an additional column as the combination of these 2 columns like

Aug
10
2 months ago
Activity icon

Replied to Laravel Query Builder Returning More Rows Than Intended

@snapey It is the foreign key of the id of the same table. If it is parent id itself then it would have 0 as parent_id else if it is a child then it would possess the id of parent category in parent_id

Could I get all the categories details based on that ame_id with some subquery or something like that? I think that should be the problem so far.

Activity icon

Started a new Conversation Laravel Query Builder Returning More Rows Than Intended

Have a table structure like:

 properties
 ------------
 id
 property_name

 buildings
 -------------
 id
 building_name
 property_id

 floors
 -------------
 id
 floor_coode
 building_id

 units
 -------------
 id
 unit_number
 floor_id

 amenities
 ------------
 id
 amenity_name
 amenity_value
 unit_id

 categories
 -----------
 id
 category_name
 parent_id

amenity_categories
 ------------
amenity_id
category_id


Now, I tried to run following query:

        $query = \DB::table('amenities')
            ->join('units', 'units.id', 'amenities.unit_id')
            ->join('floors', 'floors.id', 'units.floor_id')
            ->join('buildings', 'buildings.id', 'floors.building_id')
            ->join('properties', 'properties.id', 'buildings.property_id')
            ->leftjoin('amenity_category', 'amenities.id', 'amenity_category.amenity_id')
            ->leftjoin('categories', 'categories.id', 'amenity_category.category_id')
            ->select('amenities.id as ame_id', 'amenities.amenity_name', 'amenities.amenity_value','units.id as unit_id', 'units.unit_number','amenity_category.*','categories.parent_id as cat_parent_id')
            ->where('buildings.id',$building_id)
            ->orderBy('units.unit_number','asc');

        $data = $query->get();

With this, it is returning more row than it should be for example lets look a chunk of particular unit:107

[300] => stdClass Object
                (
                    [ame_id] => 2
                    [amenity_name] => CU
                    [amenity_value] => 20
                    [unit_id] => 1
                    [unit_number] => 107
                    [amenity_id] => 2
                    [category_id] => 8
                    [cat_parent_id] => 5
                )

            [301] => stdClass Object
                (
                    [ame_id] => 3
                    [amenity_name] => VR
                    [amenity_value] => 50
                    [unit_id] => 1
                    [unit_number] => 107
                    [amenity_id] => 
                    [category_id] => 
                    [cat_parent_id] => 
                )

            [302] => stdClass Object
                (
                    [ame_id] => 4
                    [amenity_name] => SF
                    [amenity_value] => 320
                    [unit_id] => 1
                    [unit_number] => 107
                    [amenity_id] => 4
                    [category_id] => 6
                    [cat_parent_id] => 5
                )

            [303] => stdClass Object
                (
                    [ame_id] => 1
                    [amenity_name] => BO
                    [amenity_value] => 20
                    [unit_id] => 1
                    [unit_number] => 107
                    [amenity_id] => 1
                    [category_id] => 6
                    [cat_parent_id] => 5
                )

            [304] => stdClass Object
                (
                    [ame_id] => 4
                    [amenity_name] => SF
                    [amenity_value] => 320
                    [unit_id] => 1
                    [unit_number] => 107
                    [amenity_id] => 4
                    [category_id] => 9
                    [cat_parent_id] => 5
                )

            [305] => stdClass Object
                (
                    [ame_id] => 1
                    [amenity_name] => BO
                    [amenity_value] => 20
                    [unit_id] => 1
                    [unit_number] => 107
                    [amenity_id] => 1
                    [category_id] => 8
                    [cat_parent_id] => 5
                )

            [306] => stdClass Object
                (
                    [ame_id] => 4
                    [amenity_name] => SF
                    [amenity_value] => 320
                    [unit_id] => 1
                    [unit_number] => 107
                    [amenity_id] => 4
                    [category_id] => 10
                    [cat_parent_id] => 5
                )

            [307] => stdClass Object
                (
                    [ame_id] => 1
                    [amenity_name] => BO
                    [amenity_value] => 20
                    [unit_id] => 1
                    [unit_number] => 107
                    [amenity_id] => 1
                    [category_id] => 9
                    [cat_parent_id] => 5
                )

            [308] => stdClass Object
                (
                    [ame_id] => 4
                    [amenity_name] => SF
                    [amenity_value] => 320
                    [unit_id] => 1
                    [unit_number] => 107
                    [amenity_id] => 4
                    [category_id] => 11
                    [cat_parent_id] => 5
                )

            [309] => stdClass Object
                (
                    [ame_id] => 1
                    [amenity_name] => BO
                    [amenity_value] => 20
                    [unit_id] => 1
                    [unit_number] => 107
                    [amenity_id] => 1
                    [category_id] => 10
                    [cat_parent_id] => 5
                )

            [310] => stdClass Object
                (
                    [ame_id] => 2
                    [amenity_name] => CU
                    [amenity_value] => 20
                    [unit_id] => 1
                    [unit_number] => 107
                    [amenity_id] => 2
                    [category_id] => 6
                    [cat_parent_id] => 5
                )

Here, you can see actually there are only 4 different ame_id ranging from 1-4 and that how it should be returned. Where I am doing wrong? Also, removing that pivot table is not the idea as I also need to load that relation data as well.

There are no duplicate rows, for more observation you can focus on the index 305 and 307 they are just different because of different category_id. I think I need to do something like with in eloquent. But, I don't want to use eloquent as I feel that it is quite slow as compared to the query builder.

Aug
02
2 months ago
Activity icon

Replied to The Difference Between FirstOrCreate And UpdateOrCreate

@tykus Among them which one is faster comparatively? Is it firstOrCreate who will win the race?

Activity icon

Replied to How To Up Speed For Insert?

@alex_storm so what was your last choice? I keep facing a similar situation on time to time. Even worse, I need to insert on multiple tables.

Jul
22
3 months ago
Activity icon

Started a new Conversation Queue Is Not Attempting To Run (attempts = 0)

I am trying to run the laravel queue on 5.8.

I have set QUEUE_CONNECTION=database in .env file. I have successfully dispatched job without any error and the job is stored in the jobs table.

But, even when I tried php artisan queue:work --tires=3 the attempts remains 0 and neither any error in cmd nor in laravel logs.

I have tried queue:restart and queue:listen as well but with no success.

Jul
18
3 months ago
Activity icon

Started a new Conversation Unable To Convert Timestamps From One Timezone To Another

I tried with:

    // $request->opening_time = '10:00AM'
       $date = Carbon::createFromFormat('Y-m-d H:i:s', $request->opening_time, 'MST' );
       $date->tz('UTC');
       print_r($date)

ERROR: Unexpected data found. A two-digit day could not be found Data missing

Activity icon

Replied to Rollback Not Working As Intended

Maybe it was because of that echo, maybe I might need to move that rollback above echo.

Jul
17
3 months ago
Activity icon

Started a new Conversation Rollback Not Working As Intended

My code is like following

        \DB::beginTransaction();

        try {
            $rink = Rink::create(
                [
                    'name' => $request->name,
                    'address' => $request->address,
                    'latitude' => $request->latitude,
                    'longitude' => $request->longitude,
                    'locker_room'=> isset($request->locker_room)?'1':'2',
                    'sticks_pucks'=>isset($request->sticks_pucks)?'1':'2'
                ]);

            HoursOfOperation::create(
                [
                    'rink_id' => $rink->id,
                    'opening_days' => json_encode($request->opening_days),
                    'opening_time' => $request->opening_time,
                    'closing_time' => $request->closing_time,
                    'timezone' => $request->timezone
                ]);

            Fee::create(
                [
                    'rink_id' => $rink->id,
                    'fee_per_hour' => $request->fee_per_hour,
                    'tax' => $request->tax
                ]);

        } catch (\Exception $ex) {
            echo $ex;
            \DB::rollback();
            exit(1);
        }

        \DB::commit();

In this scenario, if it encounters any problem during the creation of FEE, the Rink creation is not rolling back and still remaining there.

Jun
27
3 months ago
Activity icon

Replied to How To Convert Following Sql Query To Laravel Query Buillder?

@kima As you suggested, I tried with your answers but it showing Invalid parameter number

As there are parameters for latitude, longitude as well I tried with following:

$query  = \DB::table('branch')
            ->select(
                'id',
                'name',
                \DB::raw('( 3959 * acos ( cos ( radians(?) ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians(?) ) + sin ( radians(?) ) * sin( radians( latitude ) ) ) ) as distance',[$latitude, $longitude, $latitude])
            )
            ->having("distance", "<", $request->distance)
            ->orderBy('distance', 'asc')
            ->offset(0)
            ->limit(20);

        $data = $query->get();

But still, it's saying invalid parameter number.

Activity icon

Replied to How To Convert Following Sql Query To Laravel Query Buillder?

@mahaveer I have tried raw queries already but I could not get what I am doing wrong.

Activity icon

Replied to How To Convert Following Sql Query To Laravel Query Buillder?

@aurawindsurfing I don't find your answer helpful in any direction. Do you think that some people just rush without any sort of searching or going through documentation? You get the notification and rush to check the answers and get reply why don't you google yourself? What is that?

Anyway in case if you are looking for any more attempt how I tried this with a raw query before. Please refer to the question.

Activity icon

Started a new Conversation How To Convert Following Sql Query To Laravel Query Buillder?

$sql = "SELECT id, name, ( 3959 * acos ( cos ( radians(?) ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians(?) ) + sin ( radians(?) ) * sin( radians( latitude ) ) ) ) AS distance FROM branch HAVING distance < ? ORDER BY distance LIMIT 0 , 20";

$data = \DB::select($sql,[$latitude, $longitude, $latitude, $distance]);


I am trying to get all the branch office which is in the perimeter of a certain distance. The above code is running well with SQL query but I want to try with query builder. Could anyone suggest me its equivalent.

Update:

$query  = \DB::table('branch')
            ->select(
                'id',
                'name',
                \DB::raw('( 3959 * acos ( cos ( radians(?) ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians(?) ) + sin ( radians(?) ) * sin( radians( latitude ) ) ) ) as distance HAVING distance < ?',$request->distance)
            )
            ->orderBy('distance', 'asc')
            ->offset(0)
            ->limit(20);

        $data = $query->get();

Error

Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'HAVING distance < ? from rinks order by distance asc limit 20 offset 0' at line 1

Jun
06
4 months ago
Activity icon

Replied to Session Variable Disappeared In Controller

@SIANGBOON - I have just tried as your mentioned method, but still, it is returning an empty array.

Activity icon

Started a new Conversation Session Variable Disappeared In Controller

I am trying to store booking details using a session variable. In the first function:

public function hold(Request $request){
         $details = [
                'times' => $arr,
                'subTotal' => $subTotal,
                'tax' => $tax
            ];
            $request->session()->forget('cart');
            $request->session()->put('cart',$details);
}

Next, it will be posted to another function of same controller. Upto this point session is available.

public function checkout(){
    dd(session()->all());
}

Next route is on payment controller. This is another controller than the previous one. Here, the session variable is empty.

public function createPayment(){
    dd(session()->all());
}

What am I doing wrong? How can I access session in this createPayment function?

May
17
5 months ago
Activity icon

Replied to How To Handle Reoccuring Events

@devfrey Could you explain it in detail? I could not get it.

Activity icon

Replied to How To Handle Reoccuring Events

@devfrey do you have any suggestion about how can I design table instead or any third party library or package that handle this for me?

Activity icon

Replied to How To Handle Reoccuring Events

@devfrey could you check it I have updated the question as per your request adding some details

May
16
5 months ago
Activity icon

Started a new Conversation How To Handle Reoccuring Events

I am trying to make booking system something like booking futsal ground. Here, the user can select the time and date and make the book for it, and they can also check for repetition like, daily, weekly, monthly until xx date. This means there will be end-date predefined.

I have searched quite for a few time as some of them are quite complex or some of them are incomplete. What do you recommend to handle such tasks?

Or, if there is any package which handles all of the tasks let me know. Later, I will be integrating with a full calendar, so please consider from that frontend point of view as well.

Update:

So far I have come to the following model after quite some searching:

Events_repeat
--------------------
id
repeat_interval    `1 = daily, 2 = weekly, 3 = monthly`
repeat_date       `this is exactly the date something like 14th of every month`
ordinal        `1 = first, 2 = second, 3 = third, 4 =fourth, 5 = last`
week_days      `1 =  Sunday, 2 =  Monday,  4 = Tuesday, 8 = Wed, 16 = Thu, 32 = Fri, 64 = Sat`
start_date    `start date`
end_date    `end_date`
event_id        `foreign key`

So some examples:

*If occurs daily *

id
1 //daily
0
0
0
2019-05-17
2019-07-17

If occurs weekly

id
2 //weekly
0
0
65   //sun + sat i.e 1+32=33
2019-05-17
2019-07-17

If occurs monthly at 15th of each month

id
3 //monthly
15
0
0
2019-05-17
2019-07-17

If occurs monthly at third Friday of each month

id
3 //monthly
0
3  //third
32  //Friday
2019-05-17
2019-07-17

So, far I am convinced about storing strategy, but I am not convinced yet with its selecting strategy. I could not figure out it yet. How can fetch all the events that are going to happen in a particular month lets say at june of 2019

May
07
5 months ago
Activity icon

Replied to Validate If The Combination Of Two Columns Is Unique

@foram Yeah I have But should not it return an error and returned to form? This means currently it passed validation and tried to insert data but because of database schema exception arose.

Activity icon

Replied to Validate If The Combination Of Two Columns Is Unique

@foram I have tried with

            'before_hours' => 'required|unique:refunds,before_hours,NULL,id,bus_id,' . $request->bus_id,

Error: Integrity constraint violation: 1062 Duplicate entry '24-1' for key 'refunds_before_hours_bus_id_unique' ...

Activity icon

Started a new Conversation Validate If The Combination Of Two Columns Is Unique

Model

id, before_hours, refund_percent, bus_id

In migration:

$table->unique(['before_hours', 'bus_id']);

I find that we can make sure if a column in unique or not by

'before_hours' => 'unique:refunds,before_hours'

But, how can I validate if the combination is unique

Apr
30
5 months ago
Activity icon

Replied to Laravel Too Slow To Update 1k Records

@phoenix404 How did you fix it? Facing similar situation