kreierson

Experience

21,870

0 Best Reply Awards

  • Member Since 1 Year Ago
  • 280 Lessons Completed
  • 6 Favorites

21st April, 2017

kreierson left a reply on Custom Polymorphic Relations • 5 months ago

Try this on your info model:

protected $morphClass = 'info';

9th April, 2017

kreierson started a new conversation Randomly Lose Auth Session And Get Redirected To Login Page • 5 months ago

I seem to be losing my auth session when making api calls from my application. I followed this video https://laracasts.com/series/whats-new-in-laravel-5-3/episodes/13 to set up passport so I could use axios to make calls to my api.php in the routes folder.

Everything works perfectly when I'm using the application from the local machine.

When I browse to the application from another computer and hit a route that makes an api call, I get a status code of 302 Found and get redirected back to the login page. But the weird thing is is sometimes the request will go through just fine but eventually maybe a request or two later I will lose my session and be redirected again.

Api Routes file

Route::group(['prefix' => '/v1', 'middleware' => 'auth:api'], function () {
     /**
      * Employee Routes
      */
     Route::get('/employees', 'api\v1\[email protected]');
     Route::post('/employees', 'api\v1\[email protected]');
     Route::get('/employees/{id}', 'api\v1\[email protected]');
});

Web Routes file

Route::group(['middleware' => 'web'], function() {
     //Auth routes
     Route::group(['middleware' => 'auth'], function() {
          //Dashboard Routes
          Route::get('/dashboard', '[email protected]');

          //Calendar Routes
          Route::get('/calendar', '[email protected]');

          //Employee Routes
          Route::get('/employees', '[email protected]');
          Route::get('/employees/{id}', '[email protected]');
     });
Auth::routes();
});

Web Middleware Groups

protected $middlewareGroups = [
        'web' => [
            \App\Http\Middleware\EncryptCookies::class,
            \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
            \Illuminate\Session\Middleware\StartSession::class,
            // \Illuminate\Session\Middleware\AuthenticateSession::class,
            \Illuminate\View\Middleware\ShareErrorsFromSession::class,
            \App\Http\Middleware\VerifyCsrfToken::class,
            \Illuminate\Routing\Middleware\SubstituteBindings::class,
            \Laravel\Passport\Http\Middleware\CreateFreshApiToken::class,
        ],

I was under the impression that the CreateFreshApiToken would allow you to make axios requests to your api from your application, that is what the video states.

I also have this in my app.blade.php file

window.axios.defaults.headers.common = {
       'X-CSRF-TOKEN': Laravel.csrfToken,
       'X-Requested-With': 'XMLHttpRequest'
     };
axios.defaults.withCredentials = true;

Any guidance would be greatly appreciated.

1st March, 2017

kreierson left a reply on Authenticating With External API Using JWT? • 6 months ago

@rcastellanosm I'm looking to do this exact same thing. What did you end up going with?

Thanks

25th September, 2016

kreierson left a reply on Custom Accessor Or Attribute Casting Not Getting Called When Using Column Alias In Eloquent Query • 11 months ago

@Snapey, I think transformers is the way to go. It's working like a charm. Thanks again!

24th September, 2016

kreierson left a reply on Custom Accessor Or Attribute Casting Not Getting Called When Using Column Alias In Eloquent Query • 1 year ago

Thank you both for your time and responses! I think I'm going to do a little more research on transformers. Never used them before so now looks like a good time to learn. I think that's the best and clranest way to go about this. Thanks for the link @Snapey!

23rd September, 2016

kreierson left a reply on Custom Accessor Or Attribute Casting Not Getting Called When Using Column Alias In Eloquent Query • 1 year ago

I guess I can store all_day as a string and store "true" and "false". That solves the issue I am having. But still curious as to why the accessor isn't being called when using a column alias.

kreierson left a reply on Custom Accessor Or Attribute Casting Not Getting Called When Using Column Alias In Eloquent Query • 1 year ago

Thanks for the reply @Snapey ,

That also doesn't work, the problem is the accessor isn't even getting called. For example when I do this:

    return Trip::where('company_id', Auth::guard('api')->user()->company_id)->get(['id', 'title', 'start', 'end', 'all_day', 'url']);

I get this as a response:

[{"id":1,"title":"Bob Smith","start":"2016\/09\/12 12:00 am","end":"2016\/09\/15 12:00 am","all_day":"true","url":"\/trips\/1"}]

This is great as the accessor is getting called and converting the all_day column to "true" like I want, but I need the column name to be allDay So when I alias the column like this:

    return Trip::where('outfitter_id', Auth::guard('api')->user()->outfitter_id)->get(['id', 'title', 'start', 'end', 'all_day as allDay', 'url']);

I get this as a response:

[{"id":1,"title":"Bob Smith","start":"2016\/09\/12 12:00 am","end":"2016\/09\/15 12:00 am","allDay":1,"url":"\/trips\/1"}]

Now, the column name is what I want but it simply pulled the database column value not calling the accessor at all.

kreierson started a new conversation Custom Accessor Or Attribute Casting Not Getting Called When Using Column Alias In Eloquent Query • 1 year ago

Hello there,

I have the following eloquent query.

    Trip::where('id', $request->id)->get(['id', 'title', 'start', 'end', 'all_day as allDay', 'url']);

I am trying to cast the all_day database attribute to boolean when returning the json back to the client. Since I am using FullCalendar, I need to have the returned column as "allDay" and not "all_day", which is why I am using a column alias. If I don't column alias the all_day column both my blocks of code below work fine. But as soon as I add the column alias, it returns an integer and not boolean.

//Attribute Casting
    protected $casts = [
                'all_day' => 'boolean'
                ];
//Accessor
    public function getAllDayAttribute($value) {
        return ($value == 0 ? 'false':'true');
    }

Any help would be greatly appreciated.

20th September, 2016

kreierson left a reply on .gitignore What Should Be Ignored? • 1 year ago

I don't ignore my Vendor folder. Since I use Laravel Forge, it's nice to be able to push to a git repo then have Forge pull in the changes for me to update my website.

7th May, 2016

kreierson left a reply on Login On Mobile • 1 year ago

Just logged in and am making this comment on my Note 4 using Chrome. Looks like it's working now.

5th May, 2016

kreierson left a reply on Laravel On IIS • 1 year ago

WOW....Thank you guys for your time and input. After spending an entire day on this I got pissed and uninstalled URL Rewrite and then reinstalled. Now it works perfect. You have to love IIS. Thanks again for your help.

4th May, 2016

kreierson left a reply on Laravel On IIS • 1 year ago

I can post to http://localhost/index.php/login just fine. But having index.php in all my url's is ugly and I don't want to do that.

kreierson started a new conversation Laravel On IIS • 1 year ago

Ok so I have been trying to get this to work for days so I have finally decided to ask.

I need to get Laravel to work with IIS. My company uses windows authentication and we are building a helpdesk system. They would like it to automatically authenticate the user based on the user logged into the computer. I have everything working just fine until I try to set up a route. So if I go to http://localhost I can get there just fine. But if I set up this route

Route::post('login', 'PagesControllter@postLogin');

Then try to submit to that route I always get a 404 error back. Below is my web.config file.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.webServer>
        <handlers>
         
        </handlers>
        <rewrite>
            <rules>
                <rule name="Imported Rule 1" stopProcessing="true">
                    <match url="^(.*)/$" ignoreCase="false" />
                    <conditions logicalGrouping="MatchAll">
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
                    </conditions>
                    <action type="Redirect" url="/{R:1}" redirectType="Permanent" />
                </rule>
                <rule name="Imported Rule 2" stopProcessing="true">
                    <match url="^" ignoreCase="false" />
                    <conditions logicalGrouping="MatchAll">
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="index.php" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

I am pointing my web application in IIS to the public directory in Laravel. Any help would be greatly appreciated.

Kyle

26th April, 2016

kreierson started a new conversation Login On Mobile • 1 year ago

Whenever I try to login on my Samsung Note 4 using Chrome the site seems to just sit there and not log me in. Been trying for a week or two now. Not a huge deal as I usually watch videos on my computer, but I follow the forum on twitter and am unable to respond from my phone as I can't login to Laracasts.

25th April, 2016

kreierson left a reply on File Won't Upload • 1 year ago

Maybe it has something to do with the file size?

PHP has several configuration options to limit resources consumed by scripts. By default, PHP is set to allow uploads of files with a size of 2MB or less. Try increasing the following values in php.ini, for example: memory_limit = 32M upload_max_filesize = 24M post_max_size = 32M.

kreierson left a reply on Laravel Password Confirmation Problems • 1 year ago

Shot in the dark, sometimes I forget to change the request in my controller method.

I will sometimes do this

public function postLogin(Request $request) {
    //do stuff
}

vs using your custom request where the validation is

public function postLogin(LoginRequest $request){
    //do stuff
}

22nd April, 2016

kreierson left a reply on Giving Routes Of Different Kinds With Same URL The Same Name? • 1 year ago

Yeah that's fine. In fact if you do

Route::resource('view', 'PostController');

Then all those routes will be set up for you. Then in your terminal run php artisan route:list to view the routes that will set up for you

6th April, 2016

kreierson left a reply on "Web" Middleware In Laravel 5.2 • 1 year ago

Well this makes sense now, I was having issues flashing a message to the session as I am in development on a new project. It was working fine, but then did a composer update and flash messaging broke. I removed the web middleware group in my routes file and everything is working great now.

29th March, 2016

kreierson left a reply on Mail - From Address • 1 year ago

Thanks for the reply otepas. Mandrill does add the domain automatically but still rejects the email. The domain I am testing with is set up on GoDaddy and does have MX records configured. I decided to give Mailgun a try instead of Mandrill. Mailgun, once you have your domain configured allows you to send from any address. Depending on the recipients email provider it may show sent via "yourdomain.com" next to the from address/name, which I actually like because it's kind of a little free marketing I suppose.

kreierson started a new conversation Mail - From Address • 1 year ago

I'm looking to give my clients the ability to send emails to their customers. I was planning on using Mandrill. I can send emails just fine if I send from an email that belongs to one of my sending domains. Is it possible to change the from address to my clients email address? Currently it seems there is not using Mandrill.

 Mail::send('emails.test', [], function($message)
          {
               $message->to('clientsCustomer@customer.com')
                         ->from('clientsEmail@example.com', 'Client Name')
                         ->subject('Hello, this is a test');
                    
          });

I can add in the replyTo and that would be ok, but I would really like it to actually have my clients email rather than an email from my domain. Any thoughts?

Thanks,

15th February, 2016

kreierson left a reply on Save Form To Table • 1 year ago

In your controller, make sure you use App\Country at the top. Then typehint your Country model in your addCountry Method.

use App\Country;

public function addCountry(Country $country)
{
    $country->name = Input::get('name');
     /*$user->email = Input::get('email');
     $user->password = Hash::make(Input::get('password'));*/
        $country->save();

     return Redirect::back();
}

kreierson started a new conversation Managing Customers For Your Clients • 1 year ago

Ok, lets see if I can explain this properly.

I have a website that has my customers, lets call them businesses. These businesses provide services so they have their own customers. Our website may or may not handle the processing of payments for our customers. So we handle the credit card processing and take payment from their customer and put the money in our customers account when their customer books a service. I would like to allow their customer to either checkout as guest or create an account if they want. Either way, if they book a service with a certain business we are going to capture that information and create a customer for them so they have that data. One customer could possibly do business with multiple businesses. My question is, what is the best way to store/handle these customers?

For example Business A provides a service to Customer A. Now Business A has that customer record associated with their business. Now, Business B provides a service to Customer A, Do I attach that same customer record to Business B? Or do I create an entirely new customer record (duplicate data) for Business B? If I do that, how do allow the Customer to create an account down the road if he decides to later on? Which record would be correct. Or would it be better to associate that same customer record with Business B with a many to many relationship between the customer and business tables?

To throw another wrench in the mix, a Business can just manually create a customer as they have worked with them in the past and expect repeat business in the future. We basically want them to be able to upload their current customer database into our system so they have it stored and can do email promotions etc.

I hope this makes some sense, I know I am going in circles!

1st February, 2016

kreierson left a reply on Class View Does Not Exist • 1 year ago

Fixed it, was missing this

Illuminate\View\ViewServiceProvider::class,

in my confi/app.php under providers.

Odd that it works until I clone from bitbucket though.

kreierson started a new conversation Class View Does Not Exist • 1 year ago

I have kind of an odd thing going on. So I have my Laravel application working great on my computer. When I push it up to bitbucket, then clone it in new folder, run composer install, I get an error when composer install tries to run php artisan clear-compiled. The error is [ReflectionException] Class view does not exist. From there I cannot run any artisan command.

I found the line of code that is causing the error. In my AppServiceProvider in the boot method I have a view()->composer.

When I comment out the following code block in my boot method I can run artisan commands but I do need this variable shared with all views so I don't have to pass it in through the controller all the time.

''' view()->composer('*', function($view) { if(!Auth::guest()){ if(Auth::user()->userable_type == "Guide") { $view->with('current_guide', auth()->user()->userable); } if(Auth::user()->userable_type == "Outfitter") { $view->with('current_user', auth()->user()->userable); } } }); '''

Any thoughts would be greatly appreciated.

31st January, 2016

kreierson left a reply on How Much Middleware Is Too Much? • 1 year ago

Thank you both for your explanations. This makes a lot more sense now. For some reason I was under the impression that form request classes only worked with submitting forms. Silly oversight duh! Creating form request classes to replace the editLocation middleware would make a ton more sense and give me some more options. Thanks again @martinbean and @bobbybouwmann, much appreciated!

kreierson started a new conversation How Much Middleware Is Too Much? • 1 year ago

I'm curious if adding too much middleware to a route is bad practice? For example I have the following pieces of middleware on pretty much all my routes.

Auth - verifies a person is authenticated Wizard - verifies the user has completed the wizard (part of the registration process) Active - verifies their account is active and in good standing

Then, any get request that has an {id} attached to the route has a piece of middleware to protect the method on the controller. For example if I have a controller method called editLocation I attach some middleware called editLocation so someone can't just change the {id} in the url to edit someone else's location.

Route::get('dashboard/locations/{id}', 'LocationsController@editLocation')->middleware(['auth', 'wizard', 'active', 'editLocation']);

The middleware isn't doing a database call every time as I am usually verifying data from Auth::user()->is_active which I don't think Auth::user() does a database call every time once it's loaded. I could be wrong though as I'm pretty new to Laravel.

Just curious on anyone's thoughts.

Thanks, Kyle

15th December, 2015

kreierson left a reply on Authorization For A Non User Model • 1 year ago

Robarelli, Have you figure out how to do this yet? I am running into the same issue.

8th December, 2015

kreierson left a reply on How Can I Redirect All Request Of NotFoundHttpException To The Home Page? • 1 year ago

I don't have access to a Laravel project right now to test, but if you put a file in your views/errors folder and name it 404.blade.php it will automatically redirect to that page. Maybe you could just display a 404 page for your users or just put a redirect in that file. Also try looking for a method in your project called handleRoutingException. I'm assuming somewhere in there is where the logic is handled, but again, I don't have a project in front of me to confirm.

kreierson left a reply on Snippets In .blade.php Files • 1 year ago

@npubet I do have it working now using the following

        <scope>text.html.laravel-blade</scope>  

It is working fine now, just doesn't show the hint, which isn't a big deal. I'll try the additional scope files you have there and see if that doesn't help with the hinting. Thanks.

6th November, 2015

kreierson started a new conversation Snippets In .blade.php Files • 1 year ago

I seem to be having trouble to get snippets working in .blade.php files. Snippets work in all my controllers and models, regular .php files but I can't seem to get them working in my views .blade.php files. Is there some trick to this?

Edit Your Profile
Update

Want to change your profile photo? We pull from gravatar.com.