smadeira

smadeira

Member Since 3 Years Ago

Experience Points 4,520
Experience
Level
Lessons Completed 102
Lessons
Completed
Best Reply Awards 0
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.

16 Dec
1 month ago

smadeira left a reply on Auth In Browser / Vue App

Thanks so much @sustained. Putting everything in web.php seems to do the trick.

Longer term I may implement Passport and handle all of my api routes that way. It feels like it is a better solution.

15 Dec
1 month ago

smadeira started a new conversation Auth In Browser / Vue App

I have a browser-based app with full login/authentication abilities and that is all working fine. It uses that Laravel Auth functions.

Performance in some areas was slow with all the page refreshes so I decided to speed it up a bit. Now, I go to the site and login as before. Then I load a page via a web route called People which access to is controlled by Auth. So far so good.

To speed things up, I decided to make all the functionality on the page a Vue app. I'm running into an authentication problem. How do I make the connection between an api route (/api/people/3/update, for example) and the Auth that was used to load the page initially? Prior to loading the page, I store a number of configuration parameters in the session (connection strings to 3rd party systems that are specific to that user, for example.)

I think what I am asking is how do I link the web authentication (Auth::user(), Auth::guest() stuff and associated session data) with requests coming in from api calls from my Vue app?

02 Jul
6 months ago

smadeira started a new conversation OAuth Client Middleware

Maybe I am approaching this incorrectly but...

I have a controller with a method called person() that does stuff. It is called like this: www.example.com/person?a=123&b=asdf. Paste that into the browser or click it as a link and you get the intended results in your browser window. That is all good.

What I need to do though is check to see if the person doing this is authenticated using the oAuth authorization_code grant type on another server.

So, I have middleware that intercepts this route, gets the access_token for the person that initiated this (they are either logged in or will be prompted to login) and can save the token to a session. Now I need to go to my person() method with my original request data (a=123 and b=asdf.

As it stands, I am getting to the desired destination but the request data is from the last oAuth request (code and session_state) and not my a and b.

I can save the initial data in the session but I can't figure out how to make it look like request parameters.

How do I "save" my original request in my middleware and then grab it again before returning so that my person() method is none the wiser as to what happened with the oAuth piece?

Hope that makes sense and thanks for the help!

05 Mar
10 months ago

smadeira started a new conversation Aliases And Undefined Method In Facade

I am creating a package and everything seems to work except using an alias to reference the package. This is a fresh install of 5.6.

In my controller if I have a:

use MinistryPlatformAPI\MinistryPlatformAPI as MP;

then everything works.

But, if I try to use just the alias like this:

use MP;

then I get this error:

Symfony\Component\Debug\Exception\FatalThrowableError thrown with message "Call to undefined method MinistryPlatformAPI\Facade::authenticate()"

Here is my controller:

use MP;

class EventController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return void
     */
    public function index()
    {
        $mp = new MP();

        $mp->authenticate();

        $events = $mp->table('Events')
            ->select("Event_ID, Event_Title, Event_Start_Date, Event_End_Date, Location_ID_Table.[Location_Name], dp_fileUniqueId AS Image_ID")
            ->filter('((Events.Event_Start_Date between getdate() and dateadd(day, 30, getdate())) OR (Events.Featured_Event_Date < getdate() and Events.Event_Start_Date >= getdate())) AND Featured_On_Calendar = 1 and Visibility_Level_ID_Table.[Visibility_Level_ID] = 4 AND Event_Type_ID_Table.[Event_Type_ID] IN (1,14,19,21) AND Events.[_Approved] = 1 AND ISNULL(Events.[Cancelled], 0) = 0')
            ->orderBy('Event_Start_Date')
            ->get();

        dd($events);

    }
}

My Facade

<?php namespace MinistryPlatformAPI;

class Facade extends \Illuminate\Support\Facades\Facade
{
    /**
     * {@inheritDoc}
     */
    protected static function getFacadeAccessor()
    {
        return MinistryPlatformAPI::class;
    }
}

My Service Provider

<?php namespace MinistryPlatformAPI;


class ServiceProvider extends \Illuminate\Support\ServiceProvider
{
    /**
     * Indicates if loading of the provider is deferred.
     *
     * @var bool
     */
    protected $defer = false;

    /**
     * Register the service provider.
     *
     * @return void
     */
    public function register()
    {
        
    }

    /**
     * Bootstrap the application events.
     *
     * @return void
     */
    public function boot()
    {
        
    }
    
}

My alias in app.php:

 'MP' => MinistryPlatformAPI\Facade::class,

My provider in app.php:

MinistryPlatformAPI\ServiceProvider::class,

What am I doing wrong or how cna I best debug this problem?

05 Aug
1 year ago

smadeira started a new conversation LAravel 5.5 Minimum Requirements

5.5 is soon to be released (we hope) and I am looking for minimum system requirements. I've read php 7.0+. Any requirements for MySQL version? I was playing with OctoberCMS today and ran into an issue where the timestamps() function in Laravel 5.5 dev is setting timestamps with precision timestamp(0), for example, and MySQL 5.5 is not liking it.

So, as I go about upgrading my stack, it would be good to know what the requirements will be. I couldn't find any documentation on 5.5. Any help would be appreciated.

22 Aug
2 years ago

smadeira left a reply on Eloquent Data And Listeners

Thanks! Good point on the data changing possibilities. I'll pass the data to the Event.

21 Aug
2 years ago

smadeira started a new conversation Eloquent Data And Listeners

I have an application where I am matching a sponsor with a child. In the method where I make the child_sponsor relationship, I end up with a childId, a sponsorID and an ID for the sponsorship relationship ( in the pivot table.) I want to email the new sponsor some information and am using an Event / Listener to do that. In order to provide details in the email I need to get the detailed child and sponsor information from my models. I can do this two ways and want to get opinions on the best way to do it.

Option 1 - after saving the relationship in the store method (this would already have the IDs for the child and sponsor), execute an Eloquent query to get the child and sponsor detail info. Pass this info in the event to all the listeners. The listeners will then do what they need to do with info (one sends an email, the other updates a current activity table for statistics and there may be others someday)

Option 2 - after saving the relationship in the store method, Fire the event that will include the IDs of child and sponsor. In the listeners execute an Eloquent query to get any other information I need.

So, I guess my question is this - is it proper to have a listener doing work and accessing the database? Or, should the listener get all the information it needs and just do what it is required to do. I see benefits to both approaches and am interested in what the experts have to say.

If it matters, the listeners will eventually be queued using Amazon SQS queuing services.

Thanks in advance!

23 Oct
3 years ago

smadeira left a reply on HTMLPurifier In Laravel 5

This is awesome!!!

10 Jun
3 years ago

smadeira left a reply on Best Practice - Creating Accounts And Users

For the transaction... Can I start a transaction, call a number of methods (possibly in different classes) using Eloquent to save the data and then do a commit or rollback at the end?

I guess what I am asking is Laravel smart enough to keep track of all that's going on between the time I start the transaction and when it is completed?

09 Jun
3 years ago

smadeira started a new conversation Best Practice - Creating Accounts And Users

I have a multi-tenant app and as a superadmin I am the one that creates new accounts through a form where I collect basic info for the account as well as a username and password for the administrative user that will manage the account.

I create the account and get an account_id if successful. Now I need to create the admin user. I can think of a couple ways to do this:

  1. upon creation of the account, call a method that creates a user.

  2. upon creation of the account, dispatch a command that will create the user.

I'm leaning towards option 2 since that gets all reference to user methods out of my account classes. If I dispatch the command, how do I handle the situation where the account was created successfully but for some reason creating the user failed? I can throw an exception but who will catch it?

Any other opinions on how to create an account and the admin user?

23 Apr
3 years ago

smadeira left a reply on How To Start Learning Laravel

I haven't used it but I hear good things about Homestead. It is Laravel development in a box so you are isolated from other stuff.

I use github for my code. I don't have anything secret out there so I'm using a free account. I guess if you have client specific stuff you are protecting you would want a paid account.

I would learn Laravel 5 and not worry about 4. You are starting from scratch so no use learning something that is obsolete. There are lots of resources here to watch and read to get you up to speed. There are two learning curves with Laravel. The first and shorter one is installing and then building a website that uses Laravel. That's pretty easy. As you become more advanced and want to do more complicated things there is a steep learning curve as you learn the guts of how Laravel is built and how you tie into it. Just be aware that there will be time involved in learning the deeper you go.

PHPStorm gets my vote. It does almost everything for you, links well with github so you can do commits and pushes right from the IDE. It has a good debugger so you can step through your code when you need to. I don't use them, but it does have FTP capabilities.

Hope that helps!

22 Apr
3 years ago

smadeira started a new conversation Accessing The Id From The URL

I have this URL - example.com/users/23/edit which will display the update a user profile form for the user with id 23. That's all straight forward.

Because you can change the URL to whatever you want, what I need to do is ensure that the person editing the profile is either an admin or it is the user with ID 23. We don't want non-admins editing other profiles.

I want to do the authorization from the authorize() method in a FormRequest. What is the best way of getting the id from the URL (23 in the example)? OR, should I add the ID as a hidden field in the form so I can get to it from the Request object? Or, is there another way I should be approaching this?

Thanks for the help.

04 Mar
3 years ago

smadeira started a new conversation [L5] Set Routes For Authentication Based On URI

I have a system with two authentication paths. One for admins and one for customers. Data collected, used and stored is totally different between the two groups as is access to functionality. Based on the URI, I have different routes to different controllers to handle the authentication. I set auth.model and I created an auth.controller setting that is used by the Auth function to handle login and logout.

In 4.2 I used an app::before() filter to accomplish this task. I tried to implement this as middleware in L5 but it didn't work because the routes were read prior to the middleware being executed. I added some code to the boot method of RouteServiceProvider to create the correct routes.

My routes.php looks like this:

Route::get('/auth/login', Config::get('auth.controller') . 'Controller@getLogin');
Route::post('/auth/login', Config::get('auth.controller') . 'Controller@postLogin');
Route::get('/auth/logout', Config::get('auth.controller') . 'Controller@getLogout');

The relevant sections of RouteServiceProvider look like this:

public function boot(Router $router)
    {
        $this->setModel();
        parent::boot($router);
    }

private function setModel()
    {
        // TODO - BIG kluge until I figure out right way to do it.
        if ( array_key_exists('HTTP_HOST', $_SERVER) ) {
            $host = $_SERVER[ 'HTTP_HOST' ];
            $parts = explode('.', $host);
            if ( $parts[ 0 ] == 'app' ) {
                Config::set('auth.model', 'Missions\Http\Users\Models\Admin');
                Config::set('auth.controller', 'Users\Controllers\Admin');
                Config::set('auth.table', 'admins');
            } else {
                Config::set('auth.model', 'Missions\Http\Users\Models\Sponsor');
                Config::set('auth.controller', 'Users\Controllers\Sponsor');
                Config::set('auth.table', 'sponsors');
            }
        }
    }

The setModel() method does what it is supposed to do but I think it is a hack at best. It certainly isn't beautiful code. SO, how do I set the config parameters in config\auth.php properly? If I had access to Request::getHost() that would at least look nicer than dealing directly with the $_SERVER global.

Again, this "Works" but I don't think it is correct. Looking for some ideas on a better way to do it. Thanks in advance!

13 Feb
3 years ago

smadeira left a reply on [L5] Artisan Make Commands Custom Path

Interested in this also with respect to models and controllers and anything else if you want to use a different folder structure that what is standard. Copy/paste works but is seems unnecessary.

smadeira left a reply on How To Retrieve Serialized Data In Form::model And Populate Array Of Form::select With Multiselect

I think I understand what you are trying to do here. You are getting three sets of input, serializing them into one blob and storing them. On the edit screen you need to get the same data, deserialize them and feed that to the form.

A couple thoughts and I hope to be corrected if I am wrong...

  1. The third parameter in your Form::select is null but that is where you specify a value. This is where you want to stuff your deserialized data.

  2. In terms of serialization and deserialization, I would look at the Accessors and Mutators in Eloquent. They will let you transform the data before you store it (Mutator) or transform the data when you get it (Accessor.) Yo should be able to pass the array and serialize it in a mutator and then deserialize in an accessor and it will be transparent to anything outside the model.

I haven't tried that but it is worth a shot.

smadeira left a reply on Ability To Speed Up Playback

Windows 8.1 64 bit. Not working on Chrome but is working fine with Firefox...