itstrueimryan

itstrueimryan

Brooklyn, NY

Hire Me

Member Since 4 Years Ago

Experience Points 8,820
Experience
Level
Lessons Completed 238
Lessons
Completed
Best Reply Awards 2
Best Answer
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.

11 Sep
3 months ago

itstrueimryan started a new conversation Redirect To Index Page Instead Of View After Saving (Nova)

In Laravel Nova, if I block off access to the View pages of a Resource via a Resource Policy, I get a 403 when I create/update an instance of that resource. Is there a way to redirect to the index page of a resource after saving, as opposed to the detail page?

17 Apr
7 months ago

itstrueimryan started a new conversation Passport Creating Multiple Access Tokens For Each User

I have a password grant oauth token implementation using Passport, and if I hit the oauth/token endpoint as a user multiple times in a row, multiple oauth_access_token entries are created for that same user. Is this normal? I don't understand why I would need so many tokens for one user, and the database is just flooded with pointless entries.

26 Feb
9 months ago

itstrueimryan started a new conversation Api:auth Middleware Returning Login Screen On Unauthenticated

I have a route set up in api.php:

Route::get('test', function() {
    dd('test');
})->middleware('auth:api');

I have my app all hooked up with Passport's token system, so I get a token by hitting the endpoint /oauth/token, and then proceed to use that token to hit my api endpoints. Works great. However, when a route like the one above is sent invalid credentials, instead of getting a 401 Unauthorized error like I should, I'm getting redirected to the login page on my front end.

When I look at what is going on under the hood, I see that it gets to this method in Authenticate.php:

   protected function authenticate(array $guards)
    {
        if (empty($guards)) {
            return $this->auth->authenticate();
        }

        foreach ($guards as $guard) {
            if ($this->auth->guard($guard)->check()) {
                return $this->auth->shouldUse($guard);
            }
        }

        throw new AuthenticationException('Unauthenticated.', $guards);
    }

With testing, I've found out that it does indeed reach that bottom exception. Still, I'm getting a login screen in response in Postman so I'm not really sure what's going on. All I'm looking for is a simple 401.

08 Feb
10 months ago

itstrueimryan left a reply on Laravel 5.5: Additional Attribute For Forgot Password Form

Actually I have no idea how to do that xD

itstrueimryan left a reply on Laravel 5.5: Additional Attribute For Forgot Password Form

Thanks, I think I found it. I believe I need to overwrite the sendResetLink method in `SendsPasswordResetEmails':

public function sendResetLink(array $credentials)
    {
        // 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;
        }
        // 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(
            $this->tokens->create($user)
        );
        return static::RESET_LINK_SENT;
    }

Since SendsPasswordResetEmails calls it in its own sendsResetLinkEmail method. Thanks.

itstrueimryan started a new conversation Laravel 5.5: Additional Attribute For Forgot Password Form

Looking for some guidance on how I would add a new field to the built-in forgot password functionality. Basically, it should find the user with an email / organization combination, not just email. I have authentication working for email / organization / password, but not sure what to edit for forgot password. Thanks.

18 Jan
10 months ago

itstrueimryan left a reply on Pattern Suggestion For Requests

This is what I ended up with (couldn't use array_merge because needed to append to a sub array in rules):

parent:

class OrganizationRequest extends FormRequest
{
    /**
     * Initialize new Request instance.
     */
    public function __construct()
    {
        $this->baseRules = $this->baseRules();
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function baseRules()
    {
        $rules = [
            'name' => [
                'required', 
                'string',
                'min:2',
                'max:32',
                new MustNotBeReservedWord,
            ],
        .
        .
        .

child:

class CreateOrganization extends OrganizationRequest
{
    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        $this->baseRules['name'][] = new OrganizationMustNotExist;

        return $this->baseRules;
    }
}

itstrueimryan left a reply on Pattern Suggestion For Requests

@Snapey yeh...I guess that's what I'll settle on. I mean that's kind of what I was doing, just that baseRules is a method (since there is some logic there), and I would have to call parent::baseRules() in every child class. I was trying to avoid having to put that call in there every single time but the array_merge way of doing it makes it look pretty clean anyway. Thanks.

itstrueimryan left a reply on Pattern Suggestion For Requests

@morteza thanks, but I'm already injecting custom custom Request classes into my methods.

@goatshark yeh I knew about that, and I considered just doing it that way, but that seems to violate SRP in my mind. Do this....but if it's an update, do this instead...

¯_(ツ)_/¯

itstrueimryan started a new conversation Pattern Suggestion For Requests

So I have separate create and update validation for each set of CRUD features on my site. These usually share a lot of common validation, but update may have like one more rule or a slightly different rule here or there. So I'm trying to come up with a way to avoid duplication and maintain SRP. Instead of having completely different files for updating and creating a particular something, I was doing something like:

class UserRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return auth()->check();
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'name' => [
                'required',
                'string',

and then I would have two files that inherit from this: CreateUser and UpdateUser, e.g.:

class CreateUser extends UserRequest
{
    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        $rules = parent::rules();

        $rules['username'][] = new MustBeUniqueWithinOrganization(User::class);

    return $rules;
     }

}

The problem is, now I have to call parent::rules() (or set this in the constructor) of every child request class, and that seems like too much duplication as well. I'm struggling to think of a good pattern to use here. Any suggestions are appreciated.

03 Jan
11 months ago

itstrueimryan left a reply on RecordExists Middleware In Controller

5.5.26

Did you put the model into App\Models instead of App?

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Organization extends Model
{

itstrueimryan left a reply on RecordExists Middleware In Controller

Thanks, @martinbean. I see now that you don't need to explicitly define the edit route in the routes file with route-model binding. However, I'm experiencing a weird issue where it's searching the wrong folder for the binding class:

Class 'App\Model\Organization' not found

It's saying this even though I specified Route::model('organization', 'App\Models\Organization');. The weird thing is if I change this to App\AnythingElse\Organization, the error changes to:

Class App\AnythingElse\Organization does not exist

Why does it keep making Models singular and searching the wrong folder?

02 Jan
11 months ago

itstrueimryan left a reply on RecordExists Middleware In Controller

@martinbean I still have to do that through the routes file...I can't do it in the controller itself. Just a bummer that I have to create that extra route for the edit (and single item view) actions for every resource controller I have. No way around that?

itstrueimryan started a new conversation RecordExists Middleware In Controller

Defined a resource route with:

Route::resource('organizations', 'OrganizationController');

Now I'm trying to use the record_exists middleware in the constructor of my resource controller, a la:

public function __construct()
{
    $this->middleware('record_exists:App\Model\Organization', ['only' => ['edit']]);
}

But it results in a 404. If we look at the handle method of RecordExists:

if ($model::find($request->id) === null) {
    abort(404);
}

We can see it checks for the request id. Unfortunately, this id param is null, even though the url is something like /organizations/12/edit. Is there any way to ensure that $request->id is passed, or do I have to define every edit route specifically in my web.php file?

Route::resource('organizations', 'OrganizationController')->middleware('superadmin');
Route::get('organizations/{id}/edit', '[email protected]')->middleware( 'record_exists:App\Models\Organization');

itstrueimryan left a reply on How To Handle Failed CRUD Operation

I mean I read that, but it just re-attemps the transaction. I suppose if you try n times the chance of there still being an issue after that many attempts is incredibly small, so nothing to worry about. But I was just using that as an example. I suppose those are the main concerns here so I guess I won't add any additional exception handling.

itstrueimryan left a reply on How To Handle Failed CRUD Operation

I am passing valid data, but what if the transaction fails for another reason, like a deadlock?

itstrueimryan started a new conversation How To Handle Failed CRUD Operation

So I have a controller, OrganizationController, and its counterpart OrganizationRepository. I'm trying to figure out how I should handle errors and where. My controller action for creating new organization looks like this (where $organization represents the repository):

 $organization->create($this->validatedData($request));

        return redirect('/organizations')->with('success', 'Organization successfully created and aministrator invited via email!');

and my repository class create method looks like:

DB::transaction(function() use ($organization) {
    $organization = Organization::create([
        'name' => $data['name'],
        'slug' => slugify($data['name']),
        'account_type_id' => $data['account_type_id'],
    ]);

    Admin::create([
        'username' => $data['admin_username'],
        'email' => $data['admin_email'],
        'password' => bcrypt('secret'),
        'verified' => 1,
        'organization_id' => $organization->id
    ]);
});

My question is, what if the transaction fails? I want to show a nice flash message to the user informing them that there was a problem, but what is the best way to go about this? Should I wrap the transaction in a try/catch block, and have the redirect in the catch block with an error flash message? I feel like redirecting is more a controller thing then a repo thing...but it would be cool if I could just say $organization->create in the controller and it would only continue if the method succeeds, similar to request validation.

28 Dec
11 months ago

itstrueimryan left a reply on Any Easy Way To Pass Only One Parameter To Controller Action?

Wow! What a great find. Thanks, lostdreamer, worked perfectly.

27 Dec
11 months ago

itstrueimryan started a new conversation Any Easy Way To Pass Only One Parameter To Controller Action?

So my setup is something like this:

Route::group(['prefix' => '{organization_name}', 'middleware' => ['auth', 'administers_organization']], function () {
    /** Users */
    Route::get('/users/{id}/edit', '[email protected]')->middleware('record_exists:App\Models\User');
    Route::resource('users', 'UserController');

But for the edit action in the UserController, I'm getting both the prefix and the id parameters passed. Is there a simple way to not pass the prefix variable to any of the controller actions? The only place I'm checking this variable is in the administers_organization middleware, so I'd rather not have to add an extra unused param in a bunch of actions just to get to the second param, $id. Thanks.

19 Dec
11 months ago

itstrueimryan left a reply on SES Mail Configuration

Nvm got it working. Was just using the wrong credentials. Just FYI, you don't need to set all the MAIL_ stuff (aside from MAIL_DRIVER) for SES. In AWS, create a new user in Identity and User Management (IAM), then add a policy (or add him to a group) that has full SES permissions. Use the id and secret for that user in the .env file and you're good to go.

Another note is that you won't be able to send emails to anyone unless you get your sending limit increased. You just have to open a support case and request a limit increase, in my case it took a day to get approved. Then you are out of the SES sandbox and can send to unverified emails.

itstrueimryan started a new conversation SES Mail Configuration

So I've updated my .env file to reflect my SES account in that I've changed the driver to ses and added my ses key and secret, but what am I supposed to put for the other settings? MAIL_HOST, MAIL_PORT, etc? Is there somewhere I'm supposed to look to figure out this info?

MAIL_DRIVER=ses
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

SES_KEY=somekey
SES_SECRET=somesecret
18 Dec
11 months ago

itstrueimryan left a reply on Sending Mail On AWS

@gregrobson Thanks for the info. So if I don't wish to use SES (at least for now), using a sendmail-based program on my EC2 will allow me to send emails right out of the box? Or do I still have to create an MX record for that domain?

itstrueimryan left a reply on Sending Mail On AWS

@sutherland Just confused...do I actually NEED to use SES for sending mail from an EC2 instance? Or can I just set everything up manually? I noticed I had to request a limit increase just to be able to send emails to people not verified in the system. It seems like a lot of overhead so far, and I just want to be able to send 50-100 emails per day just to test out my app with clients.

itstrueimryan started a new conversation Sending Mail On AWS

I'm having a tough time figuring out what exactly is required to send mail from my AWS EC2 server. I don't want my app coupled to any particular mail solution, but fortunately Laravel allows me to swap out my implementation very easily.

That being said, are there any major differences between setting up an MX record and Postfix manually vs utilizing SES (Simple Email Service)? I'm just trying to figure out what the best/easiest option is here. I know that with SES you get Amazon's mail rep so nothing goes into spam, but do I also get that if I just set it up on my own? Do they even allow that? If I set up SES do I still need to install a mail program like Postfix on my server anyway? Thanks.

itstrueimryan left a reply on FindForPassport Pass Different Credentials

Alright, just going to revert all the core changes and send the organization name with the username in the initial request:

$data = [
            'username' => $this->user->username . ' ' . $this->organization->name,
            'password' => 'secret',
            'client_id' => $this->client->id,
            'client_secret' => $this->client->secret,
            'grant_type' => 'password'
        ];

itstrueimryan left a reply on FindForPassport Pass Different Credentials

Okay, I did a diff on the two project folders and there were quite a few changes to core files that I made (doh). The following files were altered to allow the findForPassport method to accept two parameters (which I need):

  • vendor/laravel/passport/src/Bridge/UserRepository.php (line 42):
$user = (new $model)->findForPassport($organizationName, $username);
  • vendor/league/oauth2-server/src/Repositories/UserRepositoryInterface.php:
public function getUserEntityByUserCredentials(
        $organizationName,
        $username,
        $password,
        $grantType,
        ClientEntityInterface $clientEntity
    );
  • vendor/league/oauth2-server/src/Grant/PasswordGrant.php:
$organizationName = $this->getRequestParameter('organization_name', $request);
        if (is_null($organizationName)) {
            throw OAuthServerException::invalidRequest('organization_name');
        }
 $user = $this->userRepository->getUserEntityByUserCredentials(
            $organizationName,
            $username,
            $password,
            $this->getIdentifier(),
            $client
        );

itstrueimryan started a new conversation FindForPassport Pass Different Credentials

I'm using Passport for OAuth, and I'm using the password grant type method. I've set up the function findForPassport as such:

public function findForPassport($organizationName, $username) {
        $organizationId = optional(Organization::where('name', $organizationName)->first())->id;

        if ($organizationId === null) return null;

        return $this->where('username', $username)->where('organization_id', $organizationId)->where('confirmed', 1)->first();
}

This is working great! However, in trying to install my repo on another server, all that is being passed to this method is the username. I have no idea where I set it so that it could send two parameters, as I've searched the project for .findForPassport, organization->name and so on and nothing turns up. I'm assuming I edited something that is not tracked in the repo (some core file), but for the life of me I just can't figure out how I did this originally. Any help is appreciated.

15 Dec
1 year ago

itstrueimryan started a new conversation Validating Multiple Fields Against Each Other

I have several rows of input fields that are the same, so I validate each field like:

channel.*.type
channel.*.name
channel.*.description

Thing is, two rows cannot have the same type selected, so is there a Laravel-y best practice to do that type of validation? Thanks.

07 Dec
1 year ago

itstrueimryan left a reply on Laravel 5.5 - Different Tables For Normal Authentication Vs Passport OAuth

When I take the approach above, i.e. change the model to App\Admin::class in auth.php, front end login works great. Basically what I'm asking is if there is a way to tell Passport specifically to use a different provider? i.e. instead of users maybe something like:

'passport_users' => [
    'driver' => 'eloquent',
    'model' => App\User.class
],

itstrueimryan started a new conversation Laravel 5.5 - Different Tables For Normal Authentication Vs Passport OAuth

Hi there. I'm using the Users table for OAuth with Passport. I have a username, password, and a third field I'm using, and I'm using the grant type password flow. It works great, users hit the OAuth endpoint and then get an access token to use the API with. However, I need to use a different model, the Admin model, for the front-facing site.

When I change the User Provider in auth.php to:

'users' => [
    'driver' => 'eloquent',
    'model' => App\Admin::class,
],

It breaks the Passport stuff. Looking for recommendations on how to approach this issue. Thanks.

05 Dec
1 year ago

itstrueimryan started a new conversation PHPUnit's SetUpBeforeClass Not Working

I'm setting up some tests and I can't get setUpBeforeClass working:

public function setUpBeforeClass()
{
        parent::setUpBeforeClass();
}

I get Fatal error: Cannot make static method PHPUnit\Framework\TestCase::setUpBeforeClass() non static

However, when I make it static, i.e.:

public static function setUpBeforeClass()
{
        parent::setUpBeforeClass();
}

I get the error ReflectionException: Class config does not exist.

FYI, the setUp method works fine, but I don't want this method to run before each test method.

itstrueimryan left a reply on OAuth W/ Grant Type=password (Resource Owner Credentials Flow)

So basically, I (auth serve) would define the client_id and client_secret? And the request would pass those defined values and be checked against?

What do you mean by "you already have a client_id that uses password credentials grant?"

Thanks for your help, I feel like I'm very close to understanding this topic.

itstrueimryan started a new conversation Passport W/ Grant Type=password (Resource Owner Credentials Flow)

I am trying to use Oauth 2 to authorize users from a mobile app to a trusted authentication/resource api. They will enter their username and password in the app and the resource will return an access token which can be used in subsequent requests.

According to https://alexbilbie.com/guide-to-oauth-2-grants/#resource-owner-credentials-grant-section-43, I need to use grant type 'password', and with this flow, I need to also send client_id and client_secret. I'm just a bit confused on where those two values are supposed to be generated from in this flow?

Thanks.

23 Jun
3 years ago

itstrueimryan started a new conversation Basic Query - Order By Count

Not sure what I'm doing wrong, but this isn't producing the right results. The query I want to replicate is simple - no relationships or anything. Just trying to get the tag_ids from tag_topic with the highest number of occurrences:

SELECT tag_id FROM `tag_topic` GROUP BY tag_id ORDER BY COUNT(tag_id) DESC LIMIT 8

And here is my Eloquent code:

$tagIds = \DB::table('tag_topic')
            ->groupBy('tag_id')
            ->orderBy(\DB::raw('count(tag_id)', 'DESC'))
            ->take(8)
            ->lists('tag_id');

And I just get some really wacky results, clearly not the right ones.

itstrueimryan started a new conversation Structuring A Laravel + Vue App

So without routing Vue seems to be more of a way to enhance an individual page rather than creating an entire single page application. Cool. But I'm still having trouble wrapping my head around how I should use Vue in my simple application.

I have two pages. One is the index, a list of "items". So when the user hits the root route he goes to the items.index view and then Vue handles retrieving all of the items by calling an api route. The items are displayed, and the user can filter these results and upvote or downvote each one. These actions are handled by Vue as well. So far so good.

The other page is an individual item page: items.view. This is where I get confused. The url is something like items/{id}-{name} and I have to check whether that item exists or not before serving up the page. So do I do that the normal way (and throw a 404 if not found) and then use Vue to grab the item again after the page loads? Or do I just load the view and then let Vue handle checking for the item and putting in some 404 text if it's not found?

Also, what if I have some model stuff that doesn't need to be altered by Vue at all? Do I load that in with Laravel and then just let Vue handle the other stuff? Where is the line between them? Should I just be going all out with Vue and only use Laravel for handling the initial routing and authentication?

I know the structure of the app is up to me but I'm really just looking for some ideas on best practices or general structure because I'm having a hard time putting it all together in my mind. Anything will help!

03 Nov
4 years ago

itstrueimryan left a reply on Where Are You All From?

Brooklyn, NY

02 Nov
4 years ago

itstrueimryan left a reply on Token Mismatch...sometimes

Nevermind, I did change something. I commented out the filter itself so I wouldn't get the error anymore. Now that I've uncommented it, I am getting the error again, about half the time. It doesn't matter which form inputs I fill out or don't fill out, I just get it sometimes.

Anyway, I'll create a new project and rebuild it and see if I still run into this issue.

itstrueimryan left a reply on Token Mismatch...sometimes

Thanks, sitesense. The lifetime is at 120...so maybe it was a Chrome thing. Not sure. It was happening with multiple forms on the site but now after I waited a bit it seems to be working fine, even after not making a single new change to the code.

¯_(ツ)_/¯

01 Nov
4 years ago

itstrueimryan started a new conversation Token Mismatch...sometimes

Hi there. Making just a basic contact form (Laravel 4.2.*), nothing I haven't done a million times...but all of a sudden I'm getting a Token Mismatch errror about half of the times I submit the form. I've commented out all the controller contact method code and reduced the form to one field, just to make sure it wasn't anything weird I was doing.

Route::post('contact', ['before'=>'csrf', 'uses' => 'SiteController@contact']);
{{ Form::open(array('url' => 'contact', 'class' => 'write-form', 'id' => 'contact-form')) }}

<div class="form-group">
    <label for="first-name">First Name</label>
    <input class="form-control" type="text" name="first_name" id="first-name" value="{{ Input::old('first_name') }}" />
</div>

I'm not using a database for this project, is the only difference from the usual. Anyone know what's going on? Thanks.

28 Oct
4 years ago

itstrueimryan left a reply on Eloquent Select

User::whereUsername($username)->first()->id

or

User::where('username', $username)->first()->id 

itstrueimryan left a reply on Deployment Approaches

Time for Mr. Way to make a video about deployment best practices xD

itstrueimryan left a reply on When To Extend A Normal Class?

Wow. What a great answer. I'm going to have to re-read it about 50 times but I really appreciated the time you put in to answer my convoluted question :)

27 Oct
4 years ago

itstrueimryan left a reply on When To Extend A Normal Class?

Right :) I get interfaces, just not regular super classes. (class Car instead of interface Car or abstract Car).

itstrueimryan left a reply on When To Extend A Normal Class?

Okay I'm tired. Obviously if you want to be able to instantiate Car instead of a specific implementation then you would use a regular class.

itstrueimryan started a new conversation When To Extend A Normal Class?

So I was watching the SOLID principles video series and a lot of it is about coding to an interface (or 3). I'm just wondering, when would I extend something other than an interface? I understand using abstract classes, especially when conforming to the Template pattern and in general when you need a defined implementation of one or two methods for all the sub classes. But what about a normal class?

class Car { bla bla bla }

class Honda extends Car {}

class Toyota extends Car {}

In what situation would Car not be an interface (or an abstract)? Why would it ever be a normal class? I can see if you have grandchild classes...at which point the classes in the middle have to be regular classes, but is this even a situation that comes up? I'm just trying to think about all the different scenarios, and it's a bit overwhelming, especially watching all of the SOLID videos at once. Could use some clarification. Thanks :D

22 Oct
4 years ago

itstrueimryan left a reply on Silly Question About Dependency Injection

Right! Took me a few minutes but now it makes perfect sense. Thanks Jeff, you're the man!

itstrueimryan started a new conversation Silly Question About Dependency Injection

What's the difference between this:

public function __construct(commandTranslator $commandTranslator)
{
    $this->commandTranslator = $commandTranslator;
}

and doing something like this instead:

public function __construct()
{
    $this->commandTranslator = new commandTranslator;
}
17 Oct
4 years ago

itstrueimryan started a new conversation Most Important Aspect Of Laravel/PHP For A Job Interview?

I was wondering what you guys thought would be the most critical aspects of development in Laravel (think a medium to large-sized application having various requirements like connecting to a bunch of APIs, having a login system, some complex database interactions, the usual), and also just PHP development in general? I have some interviews next week and I'm trying to figure out what I should prioritize brushing up on this weekend.

Obviously testing is a huge trend these days, so for that, what would you recommend as far as testing protocols and software is concerned?

I'm brushing up on the best times to use commands, service providers, events, repositories, and so on....and I'm also refreshing myself on the important design patterns and how they can be implemented in Laravel.

Any thoughts are much appreciated! Thanks.

13 Oct
4 years ago

itstrueimryan started a new conversation Angular Scope Not Updating

Hello! I know this is more Angular than Laravel, but I'm trying to integrate Angular into a Laravel project and you guys are awesome so I thought I'd post it here anyway. Basically, I have two views that share a controller and a factory. The index view (show all), and an add page for adding a new item. Unfortunately, since I'm caching the results of show all, when I add a new item and go back to the index view (without refreshing), it doesn't update the list with the new item.

How do I tell Angular that I want to use the updated version of scope (not the cached version) when (and only when) I add a new item? Here are my files:

Factory

app.factory('PagesFactory', ['$http', function(http)
{
    var factory = {};

    factory.getPages = function()
    {
        return http({ url: '/pages', method: 'GET', cache: true });
    }

    factory.storePage = function(page)
    {
        return http.post('/pages/', page);
    }
}

Controller

app.controller('PagesController', ['$scope', '$http', '$location', 'PagesFactory', function(scope, http, location, PagesFactory)
{
    // Return all pages
    PagesFactory.getPages()
        .success(function(pages) {
            scope.pages = pages;
        });

    // Store new page
    scope.addPage = function()
    {
        var page = {
            name: scope.name,
            description: scope.description,
            status: scope.status
        };

        PagesFactory.storePage(page)
            .success(function(page) 
            {
                if(typeof page.id != 'undefined')
                {
                                        // So scope is being updated...
                    scope.pages.push(page);

                                        // But when i redirect to the index page I'm still getting the cached version
                    location.path('/pages');
                }

            });
    };
}]);

Thanks for your help!

12 Oct
4 years ago

itstrueimryan left a reply on Helpers File In Laravel 5

@bashy I assumed you were talking about the class file itself.