maximl337

maximl337

Member Since 4 Years Ago

Experience Points 9,115
Experience Level 2

885 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 158
Lessons
Completed
Best Reply Awards 1
Best Reply
Awards
  • Start Your Engines Achievement

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • First Thousand Achievement

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • One Year Member Achievement

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • Two Year Member Achievement

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • Three Year Member Achievement

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • Four Year Member Achievement

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • Five Year Member Achievement

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • School In Session Achievement

    School In Session

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

  • Welcome To The Community Achievement

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • Full Time Learner Achievement

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • Pay It Forward Achievement

    Pay It Forward

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

  • Subscriber Achievement

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • Laracasts Evangelist Achievement

    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 Achievement

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • Laracasts Veteran Achievement

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • Ten Thousand Strong Achievement

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • Laracasts Master Achievement

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • Laracasts Tutor Achievement

    Laracasts Tutor

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

  • Laracasts Sensei Achievement

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • Top 50 Achievement

    Top 50

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

21 Sep
7 months ago

maximl337 left a reply on BindingResolutionException And Target Is Not Instantiable

Had the same issue - it was a typo - check your spelling guys!

17 Apr
2 years ago

maximl337 left a reply on AssertJson Fails Even Though Fragment Exists

@Lord_Sharkca

There are some new methods, I use this now:

$request->assertJsonFragment(...
24 Feb
2 years ago

maximl337 started a new conversation AssertJson Fails Even Though Fragment Exists

assertJson fails even though fragment exists in response:

    // test
    ...
    $response->assertJson([
                    'type' => 'multiple_choice'
                ]);
    ...

response dump

    .....array:3 [
      0 => {#1503
        +"id": 1
        +"title_en": "Multiple Choice"
        +"title_fr": "Multiple Choice"
        +"type": "multiple_choice"
        +"created_at": null
        +"updated_at": null
      }
      1 => {#1143
        +"id": 2
        +"title_en": "Multiple Select"
        +"title_fr": "Multiple Select"
        +"type": "multiple_select"
        +"created_at": null
        +"updated_at": null
      }
      2 => {#981
        +"id": 3
        +"title_en": "Text"
        +"title_fr": "Text"
        +"type": "text"
        +"created_at": null
        +"updated_at": null
      }
    ]
03 Feb
2 years ago

maximl337 left a reply on Laravel 5.4 Passport Axios Always Returns Unauthenticated

@lars6 Yes that is set properly aswell.

I did some debugging and it seems that its the XSRF token that is not validating.

I console.log'd the token:

console.log(window.Laravel.csrfToken);

> M2tZ8hXPJcZTNpfkjm3MGhbP1JdoiSexpFSqng3d

and this value is different from the value in the request header:

X-XSRF-TOKEN:eyJpdiI6IkthV2JoMWNLVG9rcUQ2cURGS3V1ekE9PSIsInZhbHVlIjoieTZkMzd2NjZ2Y3QwZXJOXC9HMFgxY25rRjhJbFdMcFExNHhoNDRQSGJvWG1PczFhWXg1U1BtYmJnOVpWSXNGUWswUjNwNnVKZnNNVnpRNkM5VVFGbTBnPT0iLCJtYWMiOiI1YmIwYTEwYmU1NjM0ZWM2NWE0NTgwNGM3NzI3MTRjYWY4NjhiYzhjMzIxZjU0NGVlM2UyYWExZmY5NjczNDFlIn0=

maximl337 left a reply on Laravel 5.4 Passport Axios Always Returns Unauthenticated

@Lars

Yes - the correct cookie is present in the request header.

Cookie:laravel_token=eyJpdiI6ImlxU2NYUTQ4RitSdUkwYVlSdm15NVE9PSIsInZhbHVlIjoiOVwvNHk3TzVPcEpZZ29PQ29pckJMOTlTMEVVQlwvK2dqNVhLbVwvSzJidWlncXJWMDRqazZwdVZTWFB0WGxMbFkxVWlZa2k2cmU0XC94M0dGdHhhdXNPU1lBSHRhbXhMUXpLXC8zWThJM3ZXN3FxSHNYeDVuaXJXdmcyUkp3b2J4NHM4c0t1cDNvYkhcLzBWTzZBYm8zMVZwNVk2WG5hVFhzS3pHUEVzSkR4dm50a2duM1hnemxoUVVxY2lteEtGbVNxV3NsbTNqSWFFaDN4WjlJcVdVWUtaQVwvNUEweGl2Q210cnB1cW93d2Ird0NnT2tnWWRBalJhdkF5WkN1bm8xaEppQldmUTBLWHF2am5Ja2QzS1FFOFFjTnF3PT0iLCJtYWMiOiIwNzljMTNkMjkzNGRkNTE3ODFhY2Q0MWQ0MWY3ZDgzNTQyMzcxOWJkNzgwZDI4NjI5YmViODI3NTc3NmUyYmJiIn0%3D; XSRF-TOKEN=eyJpdiI6IkMyUzBMd0pvM3NEd2hcL2c5dVVxdHFnPT0iLCJ2YWx1ZSI6IlFMbEptR095bjJuWTg5VlwvVWVBc256TTJ6SlU2b053T1l6aHg1QWhSUTdcLzJaZElpMEpPNnY0bThZV1dQWHprcDhGZ3lcL1dBWTV4SEtlc1o3bmdPdHFnPT0iLCJtYWMiOiIwZjg4Y2M1MmM5YjM

maximl337 started a new conversation Laravel 5.4 Passport Axios Always Returns Unauthenticated

I've followed the guide here:https://laravel.com/docs/5.4/passport#consuming-your-api-with-javascript

Using axios:

...
mounted: function() {

            axios.get('/api/user')
                .then(function (response) {
                    console.log(response)
                })
                .catch(function (response) {
                    console.error(response);
                });
        },

But the response is always unauthenticated, I checked to see if a laravel_token cookie is present and it is:

https://i.stack.imgur.com/rrSEh.png

03 Jan
2 years ago

maximl337 started a new conversation Regarding API Authentication And Javascript Application

I'm working on building an app with 5.3: I want to build a RESTful backend using Laravel Passport.

In this section: https://laravel.com/docs/5.3/passport#consuming-your-api-with-javascript it shows you how to use the api when using a JS front-end.

I'm confused about the authentication part though, Do I still use the web Authentication route to authenticate users in my app ? How do you guys implement this , i.e. having the authentication part be restful aswell, by maybe using Password grant ?

14 Nov
2 years ago
18 Jul
2 years ago

maximl337 left a reply on Storage_path Helper Returns Wrong Path

@thefuzzy0ne No I have not modified any paths and the root directory is not 'app'

maximl337 left a reply on Storage_path Helper Returns Wrong Path

@tomi But why is it appending /app to the path?

maximl337 started a new conversation Storage_path Helper Returns Wrong Path

I am using the grabzit library to convert video to gif using Laravels IoC container.

namespace App\Services;

use App\Contracts\VideoToGif;
use App\Clients\GrabzIt\GrabzItClient;

class GrabzitService implements VideoToGif {

...


public function save(array $input)
{

    try {

        $id = $input["id"];

        $filename = $input["filename"];

        $result = $this->client->GetResult($id);

        $destinationPath = storage_path('media/gifs');

        file_put_contents($destinationPath . "/" . $filename, $result);
    
    } catch (Exception $e) {
        throw $e;
    }
}

But I get this error:

ErrorException: file_put_contents(/app/storage/media/gifs/converted_file.gif): failed to open stream: No such file or directory in /app/app/Services/GrabzitService.php:65 

Not sure if storage_path() is suppose to return the app directory when its actually in the project root.

What am I doing wrong here?

My project is on Heroku

06 Oct
3 years ago

maximl337 started a new conversation Request In Queued Listener

I have an activity log listener attached to 'auth.login' event.

    #ActivityLogListener
    
    namespace App\Listeners;
    
    use Log;
    use Carbon\Carbon;
    use App\Activity_log;
    use Illuminate\Http\Request;
    use Illuminate\Queue\InteractsWithQueue;
    use Illuminate\Contracts\Queue\ShouldQueue;
    
    class UpdateActivityLog implements ShouldQueue
    {
        protected $request;
    
        /**
         * Create the event listener.
         *
         * @return void
         */
        public function __construct(Request $request)
        {
            $this->request = $request;
        }
    
        /**
         * Handle the event.
         *
         * @param  EventDelete  $event
         * @return void
         */
        public function handle($user)
        {
    
            // Add to Activity Log
            Activity_log::create([
                     'user_id' => $user->id, 
                     'path'  => $this->request->path(),
                     'data'  => serialize($this->request->all()),
                     'method' => $this->request->method(),
                     'ip'    => $this->request->ip()
                 ]);
    
            // Update user last activity
            $user->last_activity = Carbon::now();
    
            $user->update();
            
        }

Everything worked fine until I implemented ShouldQueue interface.

Is the request data lost after the request is complete?

How can i retain this data? I dont want this listener to obstruct the request.

maximl337 started a new conversation JWT Authentication Event

Im trying to hook into the JWT token auth

for eg:

// EventServiceProvider
....
'tymon.jwt.valid' => [
            'App\Listeners\DoSomething',
        ],
....

In my listener

//DoSomething
...
public function handle($data)
    {

        Log::info('jwt-auth', $data);

    }
...

But I dont get anything.

I event tried auth.login still nothing

The only thing that works is auth.attempt on the login route.

I want to basically capture the event that does token validation.

My end goal really is to capture all the information about the request ( user , route, data. etc ) to store in an activity log.

Also, Is there a good Activity log package for L 5.1 out there that tracks/records everything?

29 Sep
3 years ago

maximl337 started a new conversation Response Content Must Be A String Or Object Error

I'm getting a lot of these in bugsnag.

UnexpectedValueException

The Response content must be a string or object implementing __toString(), "boolean" given.

I read somewhere that this might be a utf encoding issue, but not always.

26 Aug
3 years ago

maximl337 left a reply on Papertrail For Logging

I modified @paradox answer a bit if anyone needs:

// environment specific
if (App::environment('heroku')) {
    Log::useFiles('php://stderr');
}

maximl337 started a new conversation Papertrail For Logging

How do I integrate Papertrail in my app so that I can log stuff with:

Log::info('some stuff');

My app is on Heroku

24 Aug
3 years ago

maximl337 started a new conversation Paypal Payout API

I am trying to figure out the best workflow for Paypal bulk payout:

I have everything working i.e. I can send bulk payouts and read and store responses.

I have a PaypalService class that interacts with Paypals API.

// ...

use myApp\Contracts\Payment;

class PaypalService implements Payment
{
   public function sendBatchPayout(...)
   {
     ...
   }

  public function getPayoutDetails($payout_batch_id)
  {
   ...
  }
}

// .. etc

I want to know what the ideal process is to handle bulk payouts.

for eg:

3 recipients need to get X amount

I do this with:

create batch payout.

This returns a response with the 'payout_batch_id' , and this is asynchronous.

Do I make a call to get payout batch details immidiately after to get the status? or is there a waiting period?

What part of the response am I to store in my Storage/DB, I create a record for each recipient of the bulk payout, should I assign 'payout_batch_id' to each of these records

no.5 is important since the next time I wish to send a payout I want to deduct the amount of previous successful payouts from the current payout amount.

Please help. Thank you.

14 Aug
3 years ago

maximl337 left a reply on How To Retrieve Soft Deleted Models

I am such a dork.

I use JWT for authentication and was trying to get my own account after having soft deleted it. So obviously JWT was unable to find the account coz it dsnt use with trashed.

Thnx for ur help @Ruffles

maximl337 left a reply on How To Retrieve Soft Deleted Models

@Ruffles - I looked the the DB at the record exists with a datetime stamp on deleted_at

maximl337 left a reply on How To Retrieve Soft Deleted Models

Hi it works in when i try it i php artisan tinker but when I deply it gives

{error: "user_not_found"}

maximl337 started a new conversation How To Retrieve Soft Deleted Models

How do I get a model, even if its softdeleted?

I want a method, for eg:

public function show($id) {

 // show model event if soft deleted

} 

I tried

App\Model::withTrashed()
                ->where('id', $id)
                ->get();

but it returns a "user not found" error.

22 Jul
3 years ago

maximl337 left a reply on Call To Undefined Method Illuminate\Database\Eloquent\Collection::whereIn()

try this:

return $this->goals()->whereIn('user_id', $teamMembers);

I think the problem is that you are calling "goals" without the brackets like a property not a method.

maximl337 started a new conversation Can Get 'status' In Password Reminder View

I built a password reminder system following the official docs.

I am trying to get the 'status' that is supposedly passed on successful password reset link sent.

// trait ResetsPasswords
...
/**
     * Send a reset link to the given user.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function postEmail(Request $request)
    {
        $this->validate($request, ['email' => 'required|email']);

        $response = Password::sendResetLink($request->only('email'), function (Message $message) {
            $message->subject($this->getEmailSubject());
        });

        switch ($response) {
            case Password::RESET_LINK_SENT:
                return redirect()->back()->with('status', trans($response));

            case Password::INVALID_USER:
                return redirect()->back()->withErrors(['email' => trans($response)]);
        }
    }
...

In my view

{{ $status or '' }}


but it never returns anything - even after sending the link .

Note: I'm using 'log' as my mail-driver 
19 Jul
3 years ago

maximl337 left a reply on Input::get("array") With Form Request

// in your controller
public function create(Request $request) {
    $input = $request->input();

    $array_of_item_ids = $input['item_id'];

}

maximl337 left a reply on Developing Laravel Apps On: Windows Vs Linux

I use windows and dont have any problems ( ofc you have to setup).

I use:

http://gooseberrycreative.com/cmder/

it gives you linuxy goodness in windows.

AND

http://www.heidisql.com/

DB GUI

maximl337 left a reply on Ajax Form Validation

try telling laravel which column to validate against

public function rules()
    {
        return [
            'email' => 'unique:leads,email', // the name of the email column in leads table
        ];
    }

maximl337 left a reply on Eloquent Not Saving For Some Strange Reason!

@bdschr What error do you see? paste it here if possible.

maximl337 left a reply on Eloquent Not Saving For Some Strange Reason!

Does this work?

use App\Vpnservers;
use use Illuminate\Http\Request;
...
public function admin_serverposts(Request $request)
    {
    // dd($request) <-- Debug input
        $input = $request->input()
        $request_page = Session::get('request_page');
       

        if ($request_page == 'server_add') {
            $validator = Validator::make($input, [
                'ip_address' => 'required',
                'country' => 'required',
                'cert' => 'required'
                ]);
        
                if ($validator->fails()) return redirect()->back()->withErrors($validator);
        
                 $vpnservers = Vpnservers::create($input);

        //dd($vpnservers) // <- debug
                 return redirect()->route('admin.servers');
        
            }
        }
15 Jul
3 years ago

maximl337 started a new conversation DI In Constructor Vs In Method

What are the benefits / disadvantages / best practices of DI in constructor vs in methods:

...
use App\Transformer\UserTransformer;

class UserController extends Controller
{
    protected $transformer

    function __construct(UserTransformer $transformer) {

        $this->transformer = $transformer;
    }
}

VS


use App\Transformer\UserTransformer;

class UserController extends Controller
{
    ...

    public function index(UserTransformer $transformer) {
        $users = User::all();

        return $transformer->transformCollection($users->toArray());
    }
}
13 Jul
3 years ago

maximl337 started a new conversation Get Related Model For Multiple Main Models

How can I get related models for more than one main model:

//get users where roles in 1, 2, 3

$users = App\Role::whereIn('id', [1, 2, 3])->users()->paginate(20);

//returns
BadMethodCallException with message 'Call to undefined method Illuminate\Database\Query\Builder::users()'
06 Jul
3 years ago

maximl337 left a reply on Searches In Laravel 5

You could use http://algolia.com/

Lesson: https://laracasts.com/series/search-as-a-service/episodes/1

If you want to build it yourself, try this.

  1. Identify the filters ( name / users etc)
  2. build query scopes for these filters
  3. identify facets (sorting by date etc)
  4. build query scopes for facets
  5. profit.
04 Jul
3 years ago

maximl337 started a new conversation Paginating With Related Models

I am trying to paginate related models :

This: works fine:

App\User::with('roles')->get();

This returns an empty collection

App\User::with('roles')->paginate(15);

How do I paginate the second example.

02 Jul
3 years ago

maximl337 left a reply on Validation For Primary Keys

@jekingohel

Use Case:

I am the admin of a chat room..

I wish to add users to the chat room.

POST https://awesome-chat-room-api.com/room/20/users

maximl337 started a new conversation Validation For Primary Keys

How do I make a custom FormRequest for primary keys in a pivot table?

migration:

...
$table->primary(['room_id', 'user_id']);
...

maximl337 left a reply on Private Messages

I disagree with @bashy

I would like to PM other users.

use case:

"Hey did you see @bashy 's answer. he is so sexy. I would do things to him"

01 Jul
3 years ago

maximl337 left a reply on Laravel 5 Custom Request Not Working

@JoeDawson : Yes I figured it out. By default Laravels FormRequest will return a redirect, when using POSTMAN it will simply redirect you, if unit testing it will respond with a 302, if its an ajax request it will send the json respond.

if you want you can change this behavior in Illuminate\Foundation\Http\FormRequest in the response() method, you'll understand when you see it. Although its recommended not to overwrite core files.

30 Jun
3 years ago

maximl337 left a reply on Form Request Validation Redirects

@RachidLaasri

While I do myself feel "dirty" doing it this way, the original return does not serve the purpose of my project.

I would love to write a complicated workaround to handle this, unless laravel has a way to modify the response from custom FormRequests? do you know of one?

maximl337 left a reply on Form Request Validation Redirects

I figured it out:

Modifed this method in Illuminate\Foundation\Http\FormRequest:

if ($this->ajax() || $this->wantsJson()) {
            return new JsonResponse($errors, 422);
        }

        // return $this->redirector->to($this->getRedirectUrl())
        //                                 ->withInput($this->except($this->dontFlash))
        //                                 ->withErrors($errors, $this->errorBag);

        // always return json response
        return new JsonResponse($errors, 422);

maximl337 started a new conversation Form Request Validation Redirects

I have a custom form request for a method:

when I use debug it with POSTMAN with invalid POST data it redirects to "/" .

If I test with ajax it returns 422 ( this is good ).

When i run a unit test it returns 302.

How can i catch or "render" this exception in the laravel exception handler?

29 Jun
3 years ago

maximl337 left a reply on JSON Response From Form Request

@EliasSoares Hey you were right. It was an invalid rule.

Now I'm getting a 422 (Unprocessable Entity) error but no messages?

I want to send a human readable "message" alongwith the response. Here is my ajax call after a lot of tinkering to get the message

$.ajax({
            url:form.prop('action'),
            headers: {
                'Authorization':'Bearer ' + token
            },
            method: 'GET',
            dataType: 'JSON',
            success: function(data){
              console.log(JSON.parse(data)); 
            }
      
        }); //EO ajax

maximl337 started a new conversation JSON Response From Form Request

Hey guys,

Does anyone know how to customize the response from a form request when posting via ajax? right now it just returns a 500 INTERNAL SERVER ERROR

public function rules()
    {
        return [
            'email'         => 'required|email:unique',
            'password'    => 'required'
        ];
    }

maximl337 left a reply on Laravel 5 Custom Request Not Working

@RachidLaasri So its just POSTMAN that acts this way?

maximl337 left a reply on Laravel 5 Custom Request Not Working

@RachidLaasri I dont have a view - I'm using Postman.

I understand - If the Request validation fails it will not enter the method.

How would I return a json response in that case ( when building an API ) ?

maximl337 left a reply on Laravel 5 Custom Request Not Working

@pmall No - I want to test if the request validation works.

maximl337 started a new conversation Laravel 5 Custom Request Not Working

Something weird is happening in my app:

Route:

Route::resource('users', 'UserController');

Controller:

use App\Http\Requests\UserRequest;
...

public function store(UserRequest $request) {

dd($request);

}

UserRequest:

public function authorize()
{
    return true;
}

public function rules()
{
    return [
        'email'         => 'required|email',
        'password'    => 'required'
    ];
}

When I make a POST to /users , it redirects to "/"

if I change the injection to:

public function store(Request $request)

It works as intended.

28 Jun
3 years ago

maximl337 left a reply on Laravel Is A Giant Waste Of Time

Rebuilt a full project that mongs like you build in legacy code with sql on every page and stuff like messages.php, users.php?id=123, /home.php

Legacy project -> 2 years full of bugs and extremely hard to maintain.

Laravel rebuild -> ~ 1 week ( only coz im new to laravel ) with legit routing and JWT Auth coz REST.

dont complain and learn.