FareedR

FareedR

Member Since 1 Year Ago

Experience Points
6,490
Total
Experience

3,510 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
14
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 2
6,490 XP
Nov
18
11 hours ago
Activity icon

Awarded Best Reply on How Can I Foreach Array In System Settings ?

@goldtaste @tykus i solved it , thankyou for your response

public function getWalletOption()
    {
        $wallet_options = Helpers::getSetting('wallet_amount_options');
        $json_wallet_options = json_decode($wallet_options,true);
        foreach($json_wallet_options as $wallet_option){
            $amount_option[] = [
                'key' => $wallet_option['key'],
                'text' => $wallet_option['text'],
                'value' => $wallet_option['value'],
            ];
        }
        return response()->json(['status' => true, 'amount_option' => $amount_option, 'message' => 'Successfully fetched'],200);
    }
Activity icon

Replied to How Can I Foreach Array In System Settings ?

@goldtaste @tykus i solved it , thankyou for your response

public function getWalletOption()
    {
        $wallet_options = Helpers::getSetting('wallet_amount_options');
        $json_wallet_options = json_decode($wallet_options,true);
        foreach($json_wallet_options as $wallet_option){
            $amount_option[] = [
                'key' => $wallet_option['key'],
                'text' => $wallet_option['text'],
                'value' => $wallet_option['value'],
            ];
        }
        return response()->json(['status' => true, 'amount_option' => $amount_option, 'message' => 'Successfully fetched'],200);
    }
Nov
17
1 day ago
Activity icon

Started a new Conversation How Can I Foreach Array In System Settings ?

how can i return json with data in value ?

// settings
key | value | 
options {"key"=>10,"text"=>'SGD  10',"value"=>10}

// controller 
//current solution getting an error "invalid argument to supplied foreach"

$wallet_options = Helpers::getSetting('options');
        $options = [];
        foreach($wallet_options as $wallet_option ){
            $options[] = [
                'key' => $wallet_option->key,
                'text' => $wallet_option->text,
                'value' => $wallet_option->value
            ];
        }
Nov
07
1 week ago
Activity icon

Replied to Search Hashtag Symbol In Laravel Got Null

am i right ?

1)encode #laravel from frontend 2)pass it to backend 3)decode #laravel from backend

Nov
06
1 week ago
Activity icon

Replied to Search Hashtag Symbol In Laravel Got Null

which part do i need to urlencode it ? based on what i understand is urlencode need to converted BEFORE to send it right ? frontend seems fine to me ..

Activity icon

Replied to Search Hashtag Symbol In Laravel Got Null

how can this happen ? res already sent ?keyword=#laravel , but when send to backend , didnt recognize #laravel .. any tips ? search?keyword=

Activity icon

Started a new Conversation Search Hashtag Symbol In Laravel Got Null

how can i get #laravel in my searching input ? frontend using react js and backend using laravel

//frontend
var search = #laravel
var query = '?keyword='
var res = query.concat(search)

//res output #laravel

dd($request->input('keyword');
// output = null
Nov
04
2 weeks ago
Activity icon

Replied to Redirect Authentication From API Controller To Web

@bugsysha @bugsysha based on my use case , admin doesnt need token to logged in to dashboard. just need to authenticated as web user .

Nov
03
2 weeks ago
Activity icon

Started a new Conversation Redirect Authentication From API Controller To Web

how can i use login page(react) redirect to admin dashboard ? currently i got an error " User not logged in " packages used spatie permission role . anyone ?

public function login(Request $request)
    {
        // grab credentials from the request
        $credentials = $request->only('email', 'password');

        try {
            // attempt to verify the credentials and create a token for the user
            if (! $token = JWTAuth::attempt($credentials)) {
                return response()->json([
                    "error" => "invalid_credentials",
                    "message" => "The user credentials were incorrect. "
                ], 401);
            }
        } catch (JWTException $e) {
            // something went wrong whilst attempting to encode the token
            return response()->json([
                "error" => "could_not_create_token",
                "message" => "Enable to process request."
            ], 422);
        }

        if(!Auth::user()->email_verified){
            return response()->json([
                'message' => 'Please verify your e-mail address'
            ],401);
        }

        // all good so return the token
        $user =  User::with('detail')->where('email', $request->get('email'))->get();
        if(auth()->user()->hasRole('user')){
            return response()->json([
                'user'  => $user,
                'token' => $token,
            ],200);
        }elseif(auth()->user()->hasRole('admin')){
            return redirect()->route('admin.home');
        }else{
            return response()->json([
                'status' => false,
                'message' => 'Stranger'
            ]);
        }
    }
Nov
01
2 weeks ago
Activity icon

Started a new Conversation Redirect User To Admin Dashboard From API Controller

how can I use from REACT ( PWA ) login page , to redirect Admin Dashboard ( WEB ) ? i'm using spatie laravel permissions. I got an error " User are not logged in "

// web.php
Route::get('{slug}', function() {
    return view('home');
})->where('slug', '(?!api)([A-z\d-\/_.]+)?');
Route::prefix('admin')->middleware('role:admin')->group(function(){
    Route::get('/','Admin\[email protected]')->name('admin.home');
});
// api.php
Route::group(['prefix'=> 'auth'],function(){
    Route::post('/register','API\V1\Auth\[email protected]');
    Route::post("/login",'API\V1\Auth\[email protected]');
    Route::post('/login/{social}/callback','API\V1\Auth\[email protected]')->where('social','twitter|facebook|linkedin|google|');
});

// API\Controller
public function login(Request $request)
    {
        // grab credentials from the request
        $credentials = $request->only('email', 'password');

        try {
            // attempt to verify the credentials and create a token for the user
            if (! $token = JWTAuth::attempt($credentials)) {
                return response()->json([
                    "error" => "invalid_credentials",
                    "message" => "The user credentials were incorrect. "
                ], 401);
            }
        } catch (JWTException $e) {
            // something went wrong whilst attempting to encode the token
            return response()->json([
                "error" => "could_not_create_token",
                "message" => "Enable to process request."
            ], 422);
        }

        // all good so return the token
        $user =  User::with('detail')->where('email', $request->get('email'))->get();
        if(auth()->user()->hasRole('user')){
            return response()->json([
                'user'  => $user,
                'token' => $token,
            ],200);
        }elseif(auth()->user()->hasRole('admin')){
            return redirect()->route('admin.home');
        }else{
            return response()->json([
                'status' => false,
                'message' => 'Stranger'
            ]);
        }
    }
Oct
30
2 weeks ago
Activity icon

Replied to How Can I Run Scheduler Using Controller ?

my current code for scheduler . am i correct after learn about generating command ?

// Kernel.php
protected $commands = [
        'App\Console\Commands\PaymentRelease'
    ];
protected function schedule(Schedule $schedule)
    {
        $schedule->command('payment:release')->call('\App\Http\Controllers\Admin\[email protected]_payment')->daily()->description('Payment has been released');
    }

// Commands\PaymentRelease
protected $signature = 'payment:release';
protected $description = 'Payment has been released';
Activity icon

Replied to How Can I Run Scheduler Using Controller ?

im using localhost right now . so i need to wait for production i guess ..

Activity icon

Replied to How Can I Run Scheduler Using Controller ?

so the way im doing is correct or not valid ?

Activity icon

Started a new Conversation How Can I Run Scheduler Using Controller ?

is there any missing ? i run php artisan schedule:run but terminal display " No scheduled commands are ready to run "

//controller
public function release_payment()
    {
        $now = Carbon::now();
        $deals = Deal::where('release_payment','>=',$now)->get();
        
        foreach($deals as $deal){
            $seller_id = $deal->post->user_id;
            $amount_left = $deal->amount_left;
            CommonClass::addUserTransaction($seller_id, 'Payment for '.$deal->id, $amount_left, 'Credit', null, $deal->id);
            $deal->update([
                'status' => 'Delivered',
                'release_payment' => NULL,
                'amount_left' => 0.00
            ]);
        }
    }

//Console\Kernel.php
protected function schedule(Schedule $schedule)
    {
        // $schedule->command('inspire')->hourly();
        $schedule->call('\App\Http\Controllers\Admin\[email protected]_payment')->daily()->description('Payment has been released');
    }
Activity icon

Replied to Display Dynamic Data Instead Of Static Data In FirstOrNew Method

@sinnbeck its worked now, my mistake on [ ] [ ] . thankyou @sinnbeck

Activity icon

Replied to Display Dynamic Data Instead Of Static Data In FirstOrNew Method

i need to set fee . so admin doesnt need to change fee using code . how can i use only that id for the updateOrCreate . so if next week , admin wanted to change , it only change on that id .

//current db
//fees
id | amount |
1   10.00

// current code

//to view & updateOrCreate
public function listFee()
    {
        $fee = Fee::firstOrCreate(
            ['id' => 1],
            ['amount' => 0.00]
        );

        return view('admin.fees.index',compact('fee'));
    }


// to update
    public function updateFee(Request $request)
    {
        $fee = Fee::updateOrCreate(
            ['id' => 1 ],
            ['amount' => number_format($request->get('amount'),2)]
        );

        toastr()->success('Cancellation fee has been updated');
        return redirect()->route('fee.list');
    }
Activity icon

Started a new Conversation Display Dynamic Data Instead Of Static Data In FirstOrNew Method

How can i display amount from database instead of static amount that given ..

//controller
public function listFee()
    {
        $fee = Fee::firstOrNew([
            'id' => 1,
            'amount' => 0.00
        ]);

        return view('admin.fees.index',compact('fee'));
    }

    public function updateFee(Request $request)
    {
        $fee = Fee::updateOrCreate([
            'id' => 1,
            'amount' => $request->get('amount')
        ]);

        toastr()->success('Cancellation fee has been updated');
        return redirect()->route('fee.list');
    }

// blade
<div class="block-content">
            <form action="{{ route('fee.update') }}" method="post">
            @csrf
            @method('PATCH')
                <div class="form-group">
                    <label for="input-title">Amount</label>
                    <input type="text" class="form-control" name="amount" value="{{ $fee->amount }}">
                </div>
                <div class="form-group">
                    <button type="submit" class="btn btn-alt-primary">Submit</button>
                </div>
            </form>
        </div>
Oct
29
2 weeks ago
Activity icon

Replied to How To Insert Multiple Array For New Data

i think this one is simple way but redundant code i guess ..

$rating = new Rating ([
'rater_id => //User A id 
'user_id => //User B id
]);
$rating->save()

$rating = new Rating ([
'rater_id => //User B id 
'user_id => //User A id
]);
$rating->save()
Activity icon

Replied to How To Insert Multiple Array For New Data

i just noticed about it , how can i handle it ? do you know ?

Oct
28
3 weeks ago
Activity icon

Awarded Best Reply on How To Insert Multiple Array For New Data

@vitnudi @piljac1 problem solved

$data = collect([
                        ['rater_id' => $seller_id , 'user_id' => $buyer_id , 'deal_id' => $deal->id],
                        ['rater_id' => $buyer_id , 'user_id' => $seller_id , 'deal_id' => $deal->id]
                    ]);
                    $dataArray = $data->toArray();
                    
                    Rating::insert($dataArray);
Activity icon

Replied to How To Insert Multiple Array For New Data

@vitnudi @piljac1 problem solved

$data = collect([
                        ['rater_id' => $seller_id , 'user_id' => $buyer_id , 'deal_id' => $deal->id],
                        ['rater_id' => $buyer_id , 'user_id' => $seller_id , 'deal_id' => $deal->id]
                    ]);
                    $dataArray = $data->toArray();
                    
                    Rating::insert($dataArray);
Activity icon

Started a new Conversation Search # In Searching

in "description" i put a "#laravel" . how can i search by using #laravel . still no luck on it

//route
    Route::post('/search/{search}','API\V1\[email protected]');

//controller
$posts = Post::where('location','like','%'.$search.'%')
        ->orWhere('title','like','%'.$search.'%')
        ->orWhere('description','like','%'.$search.'%')
        ->orWhereHas('user', function ($query) use ($search){
            // search in table user
            $query->where('username','like','%'.$search.'%');
        })
        ->orderBy('expired_at','desc')
        ->paginate(5);
Activity icon

Started a new Conversation How To Insert Multiple Array For New Data

I have case that if button confirmed is fire , User A and User B need to add in other table , how can I do it in eloquent ? is there any method more efficient than my code ? assume that rater id can be either buyer_id and seller_id

// deals
id | buyer_id | seller_id
1   2           3
// ratings
id | rater_id | user_id |
1   2           3
2   3           2

$rating = new Rating ([
'rater_id => //User A id 
'user_id => //User B id
]);
$rating->save()

$rating = new Rating ([
'rater_id => //User B id 
'user_id => //User A id
]);
$rating->save()
Oct
25
3 weeks ago
Activity icon

Replied to How To Calculate In Model

thankyou so much ! thankyou for your time again @sinnbeck

Activity icon

Replied to How To Calculate In Model

so meaning , i dont have to put star in my table ? just appends ?

Activity icon

Replied to How To Calculate In Model

it does add a new entry in the database , but for attribute ('star') doesn't update .

// table ratings
id | rater_id | user_id | rating |
1   1       2           2
// table users
id | star
2   2

but for table users still 0 . supposedly after rater rate user_id 2 , it should update on table users ('star')

Activity icon

Replied to How To Calculate In Model

my mistake. i already put it "$rating->save();" . but still no change in database for attribute ('star') . but when i console.log star . it appears '2' .

Activity icon

Replied to How To Calculate In Model

yup .. its like grab rating system .. passenger will rate driver, backend will process the new rating based on record in database ( based on what i know about grab ) system will update new star .

Person A rate Person B System will update and show new rating

Activity icon

Replied to How To Calculate In Model

okay . silly me for small mistake . i try to rate person A , but star doesn't update .

// this logic will fire if person B rate person A
$rating = new Rating ([
                'rater_id' => $user_id,
                'user_id' => $deal->post->user_id,
                'post_id' => $deal->post->id,
                'rating' => $request->get('rating'),
                'comment' => $request->get('comment')
            ],201);

table ratings
id | rater_id | user_id | rating | comment |
1   person B  person A    2     empty 
Activity icon

Replied to How To Calculate In Model

this one is related for display star to FrontEnd , im using JWT + React js

//User.php
protected $fillable = [
        'username', 'name', 'email', 'password','status','star'
    ];
protected $hidden = [
        'password', 'remember_token', 'wallet'
    ];
protected $appends = ['wallet_balance','star'];

public function ratings()
    {
        return $this->hasMany(Rating::class);
    }
public function getStarAttribute()
    {
        $ratingAvg = $this->id->ratings()->avg('rating');
        return round($ratingAvg);
    }

// API Controller .
    $user =  User::with('detail')->where('email', $request->get('email'))->get();
        return response()->json([
            'user'  => $user,
            'token' => $token,
        ],200);
Activity icon

Replied to How To Calculate In Model

@sinnbeck btw im getting error :( i forgot that my model User using uuid . so error come out like this. do you know how to fix it ?

message: "Call to a member function ratings() on string"
Activity icon

Replied to Schedule In Laravel

im good to go now . but still want to learn something new :) thankyou !

Activity icon

Awarded Best Reply on How To Calculate In Model

@sinnbeck can i recap what i understand with you ?

//steps
1. table user must have "star" attribute
2. make a relation between Model User and Model Rating 
// User.php
 public function ratings()
    {
        return $this->hasMany(Rating::class);
    }
// Rating.php
public function user()
    {
        return $this->belongsTo(User::class);
    }
3. make a function getFooAttribute() and inside it can make calculation
public function getStarAttribute()
    {
        $ratingAvg = Rating::where('user_id',$this->id)->avg('rating');
        return ceil($ratingAvg);
    }
4. return ceil($ratingAvg) will define as star in table user .
Activity icon

Replied to How To Calculate In Model

thankyou a lot @sinnbeck , now i understand using getFooAttribute . thankyou for your time and knowledge.

Activity icon

Replied to How To Calculate In Model

if im using relation i need to change like this ? am i right ?

public function getStarAttribute()
{
    $ratingAvg = $this->id->ratings->avg('rating');
    return ceil($ratingAvg);
}
Activity icon

Replied to How To Calculate In Model

@sinnbeck can i recap what i understand with you ?

//steps
1. table user must have "star" attribute
2. make a relation between Model User and Model Rating 
// User.php
 public function ratings()
    {
        return $this->hasMany(Rating::class);
    }
// Rating.php
public function user()
    {
        return $this->belongsTo(User::class);
    }
3. make a function getFooAttribute() and inside it can make calculation
public function getStarAttribute()
    {
        $ratingAvg = Rating::where('user_id',$this->id)->avg('rating');
        return ceil($ratingAvg);
    }
4. return ceil($ratingAvg) will define as star in table user .
Activity icon

Replied to How To Calculate In Model

@sinnbeck my final code is here? am i correct ?

    $ratingAvg = Rating::where('user_id',$this->id)->avg('rating');
        $star = ceil($ratingAvg) ;
        
        return $star;
Activity icon

Replied to How To Calculate In Model

@sinnbeck if im using avg , which part do i need to change ? can you show me plus , am i doing it correct ? first time using model for calculation

Activity icon

Replied to Schedule In Laravel

no , it just for cronjob . i guess laravel allowed this

https://stackoverflow.com/questions/36038241/laravel-scheduling-call-controller

Activity icon

Replied to How To Calculate In Model

Im so clueless about it , can you elaborate more about it ? Do i need to do like this for calculation?

//ratings
id | rater_id | user_id | rating | deal_id
1   1           2       3           1
1   1           2       4           2
1   1           2       5           3
1   1           2       1           4
1   1           2       2           5


// calculation 

$rating = Rating::where('user_id',$this->id)->get();
$totalDeal = $rating->count();
$totalRating = $rating->sum('rating');
$star = 5 

$ratingPercent = $totalRating / $totalDeal * ($star / 100) )

if($ratingPercent >= 100 ){
    $star = 5
}else if ( $ratingPercent >= 80){
    $star = 4 
}else if ( $ratingPercent >= 60){
    $star = 3
}else if ( $ratingPercent >= 40){
    $star = 2
}else if ( $ratingPercent >= 20){
    $star = 1
}else {
    $star = 0
}
return $star 
 

Oct
24
3 weeks ago
Activity icon

Started a new Conversation How To Calculate In Model

I have model of User and Rating . i need to calculate user rating based on what they get from customer rate . how can i do it ? should i make calculation in User model or Rating model ?

protected $appends = ['star']
Activity icon

Replied to Schedule In Laravel

@tykus @mo7sin i try using controller , am i correct for this one ?

// Kernel.php
protected function schedule(Schedule $schedule)
    {
        // $schedule->command('inspire')->hourly();
        $schedule->call('\App\Http\Controllers\Admin\[email protected]_payment')->daily();
    }

// Controller
public function release_payment()
    {
        $now = Carbon::now();
        $deals = Deal::where('release_payment','>',$now);
        
        foreach($deals as $deal){
            $seller_id = $deal->post->user_id;
            $amount_left = $deal->amount_left;
            CommonClass::addUserTransaction($buyer_id, 'Payment for '.$deal->id, $amount_left, 'Credit', null, $deal->id);
            $deal->update([
                'status' => 'Delivered',
                'release_payment' => NULL,
                'amount_left' => 0.00
            ]);
        }
    }
Activity icon

Replied to Schedule In Laravel

this is my full code for scheduling , i'm not understand on your statement for Closure scope . where do i need to put i ? should i make a controller for this schedule ? because in my case , cron need to check whether release payment > now() . if yes, i need to update amount on other table,

//Case 
if release payment > now 
then update balance based on amount left
protected function schedule(Schedule $schedule)
    {
        // $schedule->command('inspire')->hourly();
        $now = Carbon::now();
        $schedule->call(function(){
            DB::table('deals')
            ->where('release_payment','>',$now)
            ->update([
                'status' => 'Delivered',
                'release_payment' => NULL,
                'amount_left' => 0.00
            ]);
        })->daily()->description('Payment has been released');
    }
Activity icon

Replied to Schedule In Laravel

Console\Kernel.php. make sense for you ?

    $now = Carbon::now();
        $schedule->call(function(){
            DB::table('deals')
            ->where('release_payment','>',$now)
            ->update(['status' => 'Delivered']);
        })->daily();
Activity icon

Started a new Conversation Schedule In Laravel

In table 'deals have attribute status and it need to change if release_payment is more than now() . where should i change the status ? inside this schedule , or i need to make a new controller for it ?

$now = Carbon::now();
        $schedule->call(function(){
            DB::table('deals')->where('release_payment','>',$now);
        })->daily();
Oct
12
1 month ago
Activity icon

Started a new Conversation Middleware In Route

How can i set middleware inside of route group ?

Route::prefix('admin')->group(function(){
    Route::get('/login-form','Auth\[email protected]')->name('web.login.form');
    Route::post('/login','Auth\[email protected]')->name('web.login');

// supposedly in middleware 
    Route::get('/','Admin\[email protected]')->name('admin.home');
    
});
Sep
04
2 months ago
Activity icon

Replied to Date In Carbon

@bobbybouwmann @resin @richard for more specific on my use case

if in database are empty, the system will display on selection dropdown from January 2019 until December 2023 ( if i want 4 years onwards)

if in database already have August 2019 , in selection dropdown, will not display it. 

sorry if my question confusing you guys.
Activity icon

Started a new Conversation Date In Carbon

how can i make a query where current month and year onwards for the next 4 years . previous month and year will not display. example given ;

//database
id| month | 
1   2019-08-1 

//example
September 2019 - onwards
Aug
20
2 months ago
Activity icon

Started a new Conversation Passport Authentication

Can someone show me best practices for logout using Passport ? currently using this method for my API . should i put \Auth::logout() and \Session::flush() ? or passport already done it ?

$request->user()->token()->revoke();
        return response()->json([
            'message' => 'Successfully logged out',
            'status' => true
        ],200);
Aug
06
3 months ago
Activity icon

Replied to Eloquent Design

@michapietsch thank you for your help sir. i learn something new about this