uniqueginun

Member Since 6 Months Ago

Experience Points
15,610
Total
Experience

4,390 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
122
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start your 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-in-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 Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • evangelist 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.

  • Community Pillar

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

Level 4
15,610 XP
Apr
10
1 day ago
Apr
09
2 days ago
Activity icon

Started a new Conversation Structuring Database Table That Needs Approval For Each Update

Hello there

I'm trying to come up with the best structure for database table which the business requires approval for each update/delete action.

so when new data is entered by system user it doesn't show in the system unless approved by this user's moderator also any update/delete.

here's what I think

ideas table:
#id
#title
#desc
#status_id
#created_by
#updated_by
#action_type ===> create-update-delete
#action_date
#action_info => JSON field to store updates temporarily 
#timestamps

so when moderator rejects the action I just clear out actions fields otherwise I update table according to action_info field. if action is delete I just delete the record.

But I think there is a BETTER way to do it don't you think?

Apr
04
1 week ago
Activity icon

Replied to Livewire Pagination Issue

Yes. I'm not using Laravel {{ $resource->links() }}. but I figured out the issue. basically I have special case: my app is getting the data from another server via Http requests and I get data paginated and everything but I have to hide the URL of that server from users. so I had to build custom paginator and the issue is I'm caching the data like this:

return Cache::remember('all-data', 5, function () {
        return Model::paginate(10);
    });

so the results stays the same for 5 mintues and my solution was:

return Cache::remember('all-data-' . $request->page, 5, function () {
        return Model::paginate(10);
    });
Activity icon

Replied to Livewire Pagination Issue

it's wired mouse LOL

Activity icon

Started a new Conversation Livewire Pagination Issue

I'm using livewire pagination it works but sometimes I have to click twice to navigate to other page.

I swear to GOD it works fine if I cleared the log file before each click !!!!!!!!

Apr
03
1 week ago
Activity icon

Replied to Inertia.js / Vue Error

solved! because the @ symbol I forgot about that

Activity icon

Started a new Conversation Inertia.js / Vue Error

Hello

I'm learning inertia and I'm creating my first app. I'm creating a simple component that read-write tweets and display them.

Tweets/Index.vue

<template>
    <app-layout>
        <template #header>
            <h2 class="h4 font-weight-bold">Tweets</h2>
        </template>

        <div class="row">
            <div class="col-md-8">
                <div
                    class="py-4 d-flex align-items-center justify-content-between"
                >
                    <input
                        type="text"
                        class="mr-2 form-control"
                        v-model="tweetForm.body"
                        ref="tweetBox"
                    />
                    <jet-button @click="sendTweet">Tweet</jet-button>
                   
                </div>
                <div class="mt-4">
                    <div
                        v-if="tweets.length"
                        v-for="tweet in tweets"
                        :key="tweet.id"
                        class="px-3 py-2 mb-3 border rounded bg-dark"
                    >
                        <div class="mb-2 text-light">{{ tweet.body }}</div>
                        <div
                            class="d-flex align-items-center justify-content-between"
                        >
                            <span class="text-sm-left text-muted"
                                >by @{{ tweet.creator }}</span
                            >
                            <div class="text-sm-left text-muted">
                                {{ tweet.published_at }}
                            </div>
                        </div>
                    </div>

                    <div v-else>
                            <h6 class="text-sm-left text-muted">
                                You Haven't tweeted yet?
                                <a
                                    class="text-decoration-none"
                                    @click.prevent="$refs.tweetBox.focus"
                                    href="#"
                                    >share your first thought</a
                                >
                            </h6>
                        </div>
                </div>
            </div>
            <div class="col-md-4">
                <div class="py-4">
                    <h4 class="text-center">Trendings</h4>
                </div>
            </div>
        </div>
    </app-layout>
</template>

<script>
import AppLayout from "@/Layouts/AppLayout";
import JetButton from "@/Jetstream/Button";

export default {
    props: ["tweets"],

    data() {
        return {
            tweetForm: this.$inertia.form({
                body: ""
            })
        };
    },

    methods: {
        sendTweet() {
            this.tweetForm.post(route("tweets.store"), {
                errorBag: "sendTweet",
                preserveScroll: true,
                onSuccess: () => this.tweetForm.reset()
            });
        }
    },

    components: {
        AppLayout,
        JetButton
    }
};
</script>

controller:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Redirect;
use Inertia\Inertia;

class TweetsController extends Controller
{
    public function index(Request $request)
    {

        return Inertia::render('Tweets/Index', [
            'tweets' => $request->user()->tweets
        ]);
    }

    public function store(Request $request)
    {
        $valid = $this->validate($request, [
            'body' => 'required|max:150'
        ]);

        $request->user()->tweets()->create($valid);

        return Redirect::route('tweets.index');
    }
}

Now when I create new tweet it should re-render the component and display new tweet in no time. but I get this error ncaught (in promise) TypeError: Cannot read property 'insertBefore' of null which basically is here:

insert: (child, parent, anchor) => {
        parent.insertBefore(child, anchor || null);
    },

what is wrong with my code?

Mar
30
1 week ago
Activity icon

Replied to Laravel Sail On Windows

this I get when I run my app:

[email protected]:/mnt/d/Sites/inertia-app$ sail up -d
Creating network "inertia-app_sail" with driver "bridge"
Creating volume "inertia-app_sailmysql" with local driver
Creating volume "inertia-app_sailredis" with local driver
Creating volume "inertia-app_sailmeilisearch" with local driver
Creating inertia-app_mysql_1       ... done
Creating inertia-app_meilisearch_1 ... done
Creating inertia-app_mailhog_1     ... done
Creating inertia-app_selenium_1    ... done
Creating inertia-app_redis_1       ... done
Creating inertia-app_laravel.test_1 ... done
Activity icon

Replied to Laravel Sail On Windows

yes I installed everything. even I can see the app labeled running in docker desktop app

Activity icon

Started a new Conversation Laravel Sail On Windows

Hello guys

I followed Laravel sail documentation and installed it in my windows PC. but when I run the command:

[email protected]:/mnt/d/Sites/inertia-app$ sail up -d
Creating network "inertia-app_sail" with driver "bridge"
Creating volume "inertia-app_sailmysql" with local driver
Creating volume "inertia-app_sailredis" with local driver
Creating volume "inertia-app_sailmeilisearch" with local driver
Creating inertia-app_mysql_1       ... done
Creating inertia-app_meilisearch_1 ... done
Creating inertia-app_mailhog_1     ... done
Creating inertia-app_selenium_1    ... done
Creating inertia-app_redis_1       ... done
Creating inertia-app_laravel.test_1 ... done

and open localhost in my browser it takes me to a docker tutorial page?

when I visit http://localhost:3306/ it says This page isn’t working

Did I do something wrong?

Mar
24
2 weeks ago
Activity icon

Replied to Best Solution To A Process That Takes Some Time

I measured it and in worst cast it takes about 6 seconds!! what you think?

Activity icon

Replied to Best Solution To A Process That Takes Some Time

I must notify the user that the request is completed successfully and give him that number generated by the database procedure but I think I can show the success message first and then when the job done I SMS him the generated number??!!

Activity icon

Started a new Conversation Best Solution To A Process That Takes Some Time

Hello,

I have a controller method that perform multiple tasks. everything is working fine but one of those tasks takes more time than the others and it slows down the response. so I'm thinking about changing the approach.

the flow of tasks is this:

1- method that perform database insert and return eloquent model

2- another method that insert relationship for that model

3- the task that takes time which is basically calling a stored procedure in oracle database and perform many queries and return unique long integer number

4- update the model by that big number returned from procedure

5- do some file uploading

so what is the best way to do task no #3:

- laravel scheduled cron job

-laravel queues

if they are not the same thing

Mar
23
2 weeks ago
Activity icon

Replied to Oracle 12 Database Transaction

I will think about this one because I would have more control over database stuff

Mar
22
2 weeks ago
Activity icon

Replied to Oracle 12 Database Transaction

You know what @jlrdw something weird happened!

there is a function in ** StudentBillingService::run($request, $student); ** that producing an error and not throwing exception, so I made a change and force throwing an exception the rollback happened again!!!! when change back to error rollback not happening so now I'm sure it's because that error so the question is:

** how to rollback when throwing an error from a function and not exception!!!! **

Mar
21
3 weeks ago
Activity icon

Replied to Oracle 12 Database Transaction

the only thing changed is before I use xampp in my local development but now I use docker! but how that gonna effect such thing!! does PHP version matters?

Activity icon

Replied to Oracle 12 Database Transaction

I get the 500 response back. I intentionally throw an exception in StudentBillingService::run function to execute the catch block and rollback the transactions. the only explanation is the data is persisted anyway. the question is, could it be issue in database side?

Activity icon

Replied to Oracle 12 Database Transaction

nope. and I swear it was working.

Activity icon

Started a new Conversation Oracle 12 Database Transaction

I use DB transactions in one of my controllers, and it was working perfectly until recently is not rolling back when exception is thrown.

public function store(Request $request)
{
	DB::beginTransaction();

	try {
	
		$student = StudentsService::run($request);

		$billing = StudentBillingService::run($request, $student);

		$student->bill_no = $billing->bill_no;
		$student->save();

		DB::commit();
		return response(['student' => $student], 200);
		
	} catch (\Exception $e) {
		DB::rollBack();
		Log::debug('error occured: data should not be persisted!!!!');
		Log::error($e->getMessage());
		return response(['message' => $e->getMessage()], 500);
	}
}

When I check my log I see this message 'error occured: data should not be persisted!!!!' but when I check the db I also see the record of student inserted.

Mar
08
1 month ago
Activity icon

Started a new Conversation Docker Run Two Laravel Projects

Hello everyone,

I'm new to docker and I set up docker for two projects in my local machine. the first project is a website that consumes the second project which is Laravel API.

docker-compose.yml nginx setup for the website project

services:
    nginx:
        image: nginx:stable-alpine
        ports:
            - "80:80"

docker-compose.yml nginx setup for the API project

services:
    nginx:
        image: nginx:stable-alpine
        ports:
            - "8001:80"

I perform HTTP request from website to the API but it gives me this error:

cURL error 7: Failed to connect to localhost port 8001: Connection refused (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for http://localhost:8001/api/users/3453

But the weird part is when I copy this url http://localhost:8001/api/users/3453 and paste it in the browser it works fine. which means the port not working only inside my docker container.

Feb
21
1 month ago
Activity icon

Started a new Conversation Third Party Service To Read Data From SQLdatabase Table And Send Sms

Hello,

I have SQL table that has customers appointments and I'm looking for third-party service that can help read data from that table and send SMS reminder to customers that they booked an appointment.

Note: client doesn't want a system of any kind he want a third-party service only.

Activity icon

Started a new Conversation What Is The Diff Between Rules (alpha, Alpha_num, String)

I have a field where I want the user to only fill with char from a-z and numbers from 0-9 what should I use and what is the diff between them rules?

Feb
20
1 month ago
Activity icon

Started a new Conversation Docker On Windows

Does docker has any hardware requirements to work on windows?

Feb
16
1 month ago
Activity icon

Started a new Conversation Creating New Laravel App With Old Database

we have a Laravel application and we build it from scratch. but users who already have accounts their password won't be valid in the new application because the APP_KEY used to encrypt them is the one in the old app which was Laravel 5.2 and the new one is Laravel 8 so I guess I can't copy the old key to the new app. how to fix this issue???

Feb
15
1 month ago
Activity icon

Awarded Best Reply on Hashkey Value Of DatabaseTokenRepository In Fortify

it's the app key from config file

Activity icon

Replied to Hashkey Value Of DatabaseTokenRepository In Fortify

it's the app key from config file

Activity icon

Started a new Conversation Hashkey Value Of DatabaseTokenRepository In Fortify

what is the default value of $hashKey or where it's being set in DatabaseTokenRepository constructor

public function __construct(ConnectionInterface $connection, HasherContract $hasher,
                                $table, $hashKey, $expires = 60,
                                $throttle = 60)
{
        $this->table = $table;
        $this->hasher = $hasher;
        $this->hashKey = $hashKey;
        $this->expires = $expires * 60;
        $this->connection = $connection;
        $this->throttle = $throttle;
}
Feb
11
2 months ago
Activity icon

Started a new Conversation Overriding Password Reset Functionality In Fortify

Hello everyone!

I want to customize how fortify resetting user password and instead of using user email I want to send SMS message.

after some digging I found that fortify using [email protected] method to send the reset link to the email address.

$status = $this->broker()->sendResetLink(
    $request->only(Fortify::email())
);

this method placed at PasswordBroker class

public function sendResetLink(array $credentials, Closure $callback = null)
    {
        // First we will check to see if we found a user at the given credentials and
        // if we did not we will redirect back to this current URI with a piece of
        // "flash" data in the session to indicate to the developers the errors.
        $user = $this->getUser($credentials);

        if (is_null($user)) {
            return static::INVALID_USER;
        }

        if ($this->tokens->recentlyCreatedToken($user)) {
            return static::RESET_THROTTLED;
        }

        $token = $this->tokens->create($user);

        if ($callback) {
            $callback($user, $token);
        } else {
            // Once we have the reset token, we are ready to send the message out to this
            // user with a link to reset their password. We will then redirect back to
            // the current URI having nothing set in the session to indicate errors.
            $user->sendPasswordResetNotification($token);
        }

        return static::RESET_LINK_SENT;
    }

this class also uses DatabaseTokenRepository class to handle tokens.

Now I want to override the PasswordResetLinkController class business by overriding the following:

1) sendResetLink function in PasswordBroker class.

2) couple of methods in DatabaseTokenRepository class because I changed password-resets table.

I think I will have to create my own controller that extends the PasswordResetLinkController and another class that extends PasswordBroker and another one for DatabaseTokenRepository internal business. in other words I must create new class for every class I'm planning to override!! is that true or there is easier way to do that?

Feb
09
2 months ago
Activity icon

Replied to Logout Other Devices

Yeah yeah I always do that. thank you very much. I removed the mutator and it works fine now.

Feb
08
2 months ago
Activity icon

Started a new Conversation Logout Other Devices

Hello,

I'm using auth()->logoutOtherDevices($request->password) function to logout other active sessions. it's working fine but it changes the password of the user. so when I logout the current session and try to login again it gives me wrong password.

Note: I use bcrypt() helper when creating new user but I'm sure it's identical to Hash::make

Feb
07
2 months ago
Activity icon

Started a new Conversation Livewire With Captcha Package

Hello,

I use this package https://github.com/mewebstudio/captcha to protect my forms. I used it in login form and it worked perfectly, but in register form and because I use livewire in registration every time livewire make a trip to the server the session value of the captcha changes in the server while still holds the old value in the browser.

I removed the wire:ignore from the div holds the captcha html but still not working!!

any possible work around without making all my wire:model defer???

Activity icon

Replied to Laravel Fortify - Override Login Request Validation

this will give:

Argument 1 passed to App\Providers\FortifyServiceProvider::App\Providers\{closure}() must be an instance of App\Http\Requests\LoginRequest, instance of Laravel\Fortify\Http\Requests\LoginRequest given
Feb
02
2 months ago
Activity icon

Started a new Conversation Group Data By Relationship

I have three models in my project:

Application: id, user_id, application_type, status_id
Status: id, code, description_id

I set up relationships like so:

//Application.php
public function status()
{
     return $this->belongsTo(Status::class);
}

I want to group by applications by application_type and get count of each type but also as a side info I want to know how many of that type that has status_id = 3;

Like this:

type type_1 ====== count 4 ====== status_3_count (3)

Jan
25
2 months ago
Activity icon

Awarded Best Reply on Searching Collection By Key

I did it like:

$collection->->filter(function ($item, $key) use ($keyword) {
     return Str::contains($key, $value);
}); 
Activity icon

Replied to Searching Collection By Key

I did it like:

$collection->->filter(function ($item, $key) use ($keyword) {
     return Str::contains($key, $value);
}); 
Activity icon

Started a new Conversation Searching Collection By Key

Hello,

I have a collection that looks like this:

$collection  = [
	'Laravel': 600155,
	'Django': 4234,
	'Rails': 2434
];

I want to filter it by keys something like:

$keyword = 'vel';

$collection->filter(function($framework, $key) use ($keyword) {
	return $key->match($keyword);
});
Jan
22
2 months ago
Activity icon

Started a new Conversation Livewire Charts

I'm building Apex-Charts inside livewire component like this:

<div class="row justify-content-center mt-lg-5">

    <p class="font-monospace text-center text-danger">
        chart data for: {{ $filter }}
    </p>

    <div class="col-sm-3 mb-3">
        <select class="form-control" wire:model="filter">
            @foreach($filters as $filter)
                <option value="{{ $filter }}">{{ $filter }}</option>
            @endforeach
        </select>
    </div>

    <div class="col-6">
        <div id="chart"></div>
    </div>


    @slot('scripts')

        <script>

            window.addEventListener('DOMContentLoaded', (event) => {
                renderChart(@json($chartData));
            });


            window.addEventListener('renderChart', ({detail}) => {
                renderChart(detail.data);
            }, false);

            const renderChart = chartData => {

                const counts = chartData.map(item => item.count);
                const years = chartData.map(item => item.year);

                const chart = new ApexCharts(document.querySelector("#chart"), {
                    chart: {
                        type: 'line'
                    },
                    series: [{
                        name: 'sales',
                        data: counts
                    }],
                    xaxis: {
                        categories: years
                    }
                });

                chart.render();
            }

        </script>

    @endslot

</div>

Component class

<?php

namespace App\Http\Livewire;

use Illuminate\Support\Facades\DB;
use Livewire\Component;

class Charts extends Component
{
    public $filter = 'male';

    public $chartData;

    public function mount()
    {
        $this->chartData = $this->getCollection();
    }


    public function updatedFilter($value)
    {
        $this->loadChartData();
    }

    public function render()
    {
        return view('livewire.charts', [
            'filters' => DB::table('sales')
                            ->distinct('seller_type')
                            ->pluck('seller_type')
        ]);
    }

    public function loadChartData()
    {
        $this->dispatchBrowserEvent('renderChart', [
            'data' => $this->getCollection()
        ]);
    }


    private function getCollection()
    {
        return DB::table('sales')
            ->selectRaw('count(*) as count, selling_year as year')
            ->groupBy('selling_year')
            ->orderBy('selling_year')
            ->where('seller_type', $this->filter)
            ->get();
    }
}

now the above code is working and everything but notice I have to use this public property $chartData just for the first time when component initialized because front-end won't be able to listen to renderChart event fired from the backend because component won't be initialized yet so I have to send some data to create the chart. and I can't keep using it relaying on that changing $filter variable would change $chartData and the component will render the filtered data again because it is'nt working.

so I had to create this public property to render chart at first time and then firing event and send data to it every time.

my question is: I know there's a better way to do this!!

Jan
21
2 months ago
Activity icon

Started a new Conversation Formatting Data For Charts

I have a table where I need to format data in specific way to display in charts:

categories: [
                       "01/01/2020 GMT",
                        "01/02/2020 GMT",
                        "01/03/2020 GMT",
                        "01/04/2020 GMT",
                        "01/05/2020 GMT",
                        "01/06/2020 GMT",
                        "01/07/2020 GMT",
                        "01/08/2020 GMT",
                        "01/09/2020 GMT",
                        "01/10/2020 GMT",
                        "01/11/2020 GMT",
                        "01/12/2020 GMT",
                        "01/13/2020 GMT",
                        "01/14/2020 GMT",
                        "01/15/2020 GMT",
                        "01/16/2020 GMT",
                        "01/17/2020 GMT",
                        "01/18/2020 GMT",
   ]

now in my database I may not have records in some days so when I build my query

DB::table('orders')
                    ->whereNotNull('order_no')
                    ->whereDate('created_date', '>=', Carbon::now()->subDays(60))
                    ->selectRaw('count(*) day_count, trunc(created_date) day')
                    ->groupByRaw('trunc(created_date)')
                    ->orderByRaw('trunc(created_date)')
                    ->get();

if a day doesn't has any records then it will not be included in the result of the query, how do I grab all dates for the last 30 days. Do I have to use collection again and generate another output ?

Jan
20
2 months ago
Activity icon

Replied to Livewire Component Doesn't Working As Expected

the data binding and when I submit the form it reloads the page!!

I wanted to press reply button I accidently pressed best answer one.

Activity icon

Started a new Conversation Livewire Component Doesn't Working As Expected

why this livewire component does not work as it should be:

component view:

<div class="row justify-content-center mt-5">
    <div class="col-9">
        <form wire:submit.prevent="publish">
            <div class="mb-3">
                <label for="title" class="form-label">Post title</label>
                <input wire:model="title" type="text" class="form-control" id="title">
                @error('title') <div class="invalid-feedback"> {{ $message }} </div> @enderror
            </div>
            <div class="mb-3">
                <label for="body" class="form-label">Body</label>
                <textarea wire:model="body" class="form-control" id="body" rows="3"></textarea>
                @error('body') <div class="invalid-feedback"> {{ $message }} </div> @enderror
            </div>
            <div class="mb-3">
                <button type="submit" class="btn btn-primary">Publish</button>
                <button wire:click="discard" type="button" class="btn btn-danger">Discard</button>
            </div>
        </form>
    </div>
</div>

component class:

<?php

namespace App\Http\Livewire;

use Livewire\Component;

class PostCreate extends Component
{
    public $title = 'post title';

    public $body = 'post body';

    protected $rules = [
        'title' => 'required|string|max:120|min:10',
        'body' => 'required|string'
    ];

    public function updated($propertyName)
    {
        $this->validateOnly($propertyName);
    }

    public function publish()
    {
        $validatedData = $this->validate();

        dd($validatedData);
    }

    public function discard()
    {
        $this->reset(['title', 'body']);
    }

    public function render()
    {
        return view('livewire.post-create');
    }
}
Jan
18
2 months ago
Activity icon

Started a new Conversation How To Logout Other Sessions For A User When Using File Driver

what is the safest way to logout user from other devices when using file driver for sessions?

Activity icon

Awarded Best Reply on Storing Session Data In Database

solved. make middleware and store data from within it instead of event listener.

Activity icon

Replied to Storing Session Data In Database

solved. make middleware and store data from within it instead of event listener.

Activity icon

Started a new Conversation Storing Session Data In Database

I'm using file sessions driver in my app and I want to store data in my sessions table not for maintaining user session but just to track user login activity. where should I but my piece of code? I put it in listener for login event and the data inserted successfully but the session id stored in database table doesn't equal session id of the file.

Here's my handle function in my listener class

public function handle($event)
{

    try {
        $data = [
            'id' => session()->getId(),
            'user_id' => request()->user()->id,
            'ip_address' => request()->ip(),
            'user_agent' => request()->userAgent(),
            'last_activity' => Carbon::now()->getTimestamp()
        ];

        Session::updateOrCreate($data, $data);

    } catch (\Exception $exception) {

    }
}
Activity icon

Replied to Payload Column In Sessions Table

now I'm using file driver session in my app and I want to store data in my sessions table not for maintaining user session but just to track user login activity. where should I but my piece of code? I put it in listener for login event and the data inserted successfully but the session id stored in database table doesn't equal session id of the file.

Activity icon

Replied to Payload Column In Sessions Table

yeah, when I investigated the code I found this.

Activity icon

Started a new Conversation Payload Column In Sessions Table

I was wondering what is the big string stored in payload column in sessions table used for?

Jan
17
2 months ago
Activity icon

Awarded Best Reply on Laravel Jetsream Session Table

I found it. it's in

class DatabaseSessionHandle
{
	public function write($sessionId, $data)
    {
        $payload = $this->getDefaultPayload($data);

        if (! $this->exists) {
            $this->read($sessionId);
        }

        if ($this->exists) {
            $this->performUpdate($sessionId, $payload);
        } else {
            $this->performInsert($sessionId, $payload);
        }

        return $this->exists = true;
    }
}
Activity icon

Replied to Laravel Jetsream Session Table

I found it. it's in

class DatabaseSessionHandle
{
	public function write($sessionId, $data)
    {
        $payload = $this->getDefaultPayload($data);

        if (! $this->exists) {
            $this->read($sessionId);
        }

        if ($this->exists) {
            $this->performUpdate($sessionId, $payload);
        } else {
            $this->performInsert($sessionId, $payload);
        }

        return $this->exists = true;
    }
}
Activity icon

Started a new Conversation Laravel Jetsream Session Table

Hello,

I'm trying to find the code where Jetstream inserts data into sessions table. I believe it's a listener for login event. but I couldn't find it.