jeudi 19 janvier 2017

Adding a composer package to Laravel 5

"require": {
    "infusionsoft/php-sdk": "^1.2",
    "laravel/lumen-framework": "5.1.*",
    "vlucas/phpdotenv": "~1.0",
    "barryvdh/laravel-debugbar": "^2.2",
    "goaop/framework": "^2.0",
    "php-http/httplug": "^1.1",
    "infusionsoft/old-php-isdk": "*"
},

I'm trying to use the "infusionsoft/old-php-isdk" which is in the packagist composer repository but it's not specific to Laravel. I'm using an order controller and it's code that I picked up from another developer so he references the current (and working) "infusionsoft/php-sdk" as the following

"use infusionsoft\infusionsoft;"

What namespace do I call it if it has no namespace from the package?

Here's the original link to the composer package. http://ift.tt/1EKzsba

Am I missing something? Do I need to assign it a namespace? What and where would I put it?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2iH5f9U
via IFTTT

Laravel Valet not working- as if it's missing a web server

I followed the instructions to install Valet and it worked fine the first 2 days with no problems at all. Then out of nowhere it stopped working and only seemed to get worse with time. First there were 404 errors on all laravel projects beyond their homepage and eventually the sites stopped working altogether as if there isn't a web server running.

Here are some details about my environment:

  • Running macOS Sierra, PHP 7.1, MariaDB

  • Composer works fine and is in path

  • Valet 2.0.3 (latest at the time of writing this)

  • Changed MAMP to default ports to free up ports 80 and 3306 before installing and running Valet the first time

  • Pinging something.dev returns 127.0.0.1 as it should

  • Running something.dev in browser does not work D if there is no web server running

After hours of searching, fiddling, uninstalling and reinstalling everything I am now at a very bizarre point. If MAMP is running on ports 80 and 3306 Valet will serve something.dev although I still get 404 beyond the homepage. How can this be? Isn't MAMP supposed to be on other ports to free up 80 and 3306 for Valet or not running at all? The other strange thing is that something.dev will return my webroot which is Valet parked and not the site something.dev which is under the webroot. I have searched high and low and I am at a loss as to how I can get things running the way they should be



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2iYALig
via IFTTT

How to call laravel backend api from angular 2

I am developing a website fronted in angular2 and an api in laravel with dingo. Now I want to get the data from this api in angular 2. But of course I want to protect the api so that for now only my angular fronted is allowed to get get a response from the api.

I searched a lot but can not figure out the best way. Most results in searching use jwt or auth, but with anangular 2 application where user have to login. In my case no login is required to go to pages with data from the api.

I would appreciate any suggestions or links to interesting tutorials or othe question on this topic.

Thanks!



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2iYdey4
via IFTTT

secure register form from preventing html injection

Hello im creating a app that haves 2 type of users (employer, jobseeker), but i have a security issue (html injection), in my form i have a hidden field that calls "account_type_id" where i in the AuthController check the type of account, and depending of the account type i validate or create this type of user data. At first i wanted to use in the same controller the registration of different users, but now im not quite sure how i could check in the AuthController wich type of user is being register, the only difference i notice in both of them is that they use different routes where each one use different register forms.

How could i check wich type of user being register without using hidden fields on the form?

Example code:

AuthController:

protected function validator(array $data)
    {

        $accountType = AccountType::find($data['account_type_id']);


        if($accountType->name === "employer"){
            return Validator::make($data, [
                //employer validation
            ]);
        }else{
            return Validator::make($data, [
     //candidate validation
                ...
            ]);
        }

    }

    /**
     * Create a new user instance after a valid registration.
     *
     * @param  array  $data
     * @return User
     */
    protected function create(array $data)
    {

        // Check type of account
        $accountType = AccountType::find($data['account_type_id']);


        if($accountType->name === "employer"){

            //employer create


        }else{

            //Candidate user create

        }


        return $user;
    }



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2jRf2qZ
via IFTTT

Laravel route not defined but it clearly is

I keep getting the following error in Laravel 5.3:

Route [clients] not defined. (View: /srv/users/serverpilot/apps/project-sytem/resources/views/partials/sidebar.blade.php) (View: /srv/users/serverpilot/apps/project-sytem/resources/views/partials/sidebar.blade.php) (View: /srv/users/serverpilot/apps/project-sytem/resources/views/partials/sidebar.blade.php)

Here is my routes file:

Route::group(['middleware' => 'auth'], function () {
    Route::get('/', 'ProjectController@index')->name('projects');
    Route::get('/projects', 'ProjectController@index')->name('projects');
    Route::resource('projects', 'ProjectController');


    Route::get('/clients', 'ClientController@index')->name('clients');
    Route::resource('clients', 'ClientController');

});


Auth::routes();

Route::get('/home', 'HomeController@index');

In my sidebar.blade.php I have links to my routes like this:

<li>
   <a href=""><i class="fa fa-archive" aria-hidden="true"></i> Projects</a>
</li>
<li>
   <a href=""><i class="fa fa-users" aria-hidden="true"></i>Clients</a>
</li>

I don't see where I'm going wrong, my projects route works just fine and I've done it the exact same way. Any ideas what's going wrong with my clients route?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2k5yjV7
via IFTTT

Laravel 5.3 whereIn from existing collection - optimise

I have a table with test dates (Test) and a table with results for each of those test dates (Results). I first get all the Test records for a particular athlete/customer. Then I need to get all the results for each of those test records. I only manage to get it working with a foreach loop. 1. Is there a more optimal way to structure the query? 2. For blade, is it perhaps more structured to have the array ordered per test_id? In blade I display the test data as headers and the results for each of those underneath.

First option below with sub query doesn't work. Get a db table not found error:

$athlete_tests = Test::where('athlete_id', $an_athlete->id)->get();
    if($athlete_tests){
        $results = Result::whereIn('test_id', function($query) use ($an_athlete){
                    $query->select('test_id')
                        ->from('Test')
                        ->where('athlete_id', $an_athlete->id);
                })->get();   
    }                 

This one works - must be optimised:

$athlete_tests = Test::where('athlete_id', $an_athlete->id)->get();
    if($athlete_tests){
        $results = collect([]);

        foreach ($athlete_tests as $key => $value) {
            $results = $results->merge(Result::where('test_id', $value->id)->get());
        }                    
    }



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2iXXuuU
via IFTTT

Angular File Upload via Laravel Controller

I need to upload image and video files to the server in an Angular application using Laravel 5.1 as the back end. All Ajax requests need to go to the Laravel controller first, and we have the code there for how the file gets handled when it gets there. We have previously done normal HTML forms to submit file uploads to the controller, but in this case we need to avoid the page refresh of a form, so I am attempting this in Ajax through Angular.

What information do I need to send to the Laravel controller with Ajax that was being sent to the controller via an HTML form previously?

This is the code in the Laravel controller that handled the file information once it got there. That's what I need to figure out how to send, so I can hopefully reuse this code:

    $promotion = Promotion::find($id);
    if (Input::hasFile('img_path')){
        $path             = public_path().'/images/promotion/'.$id.'/';
        $file_path        = $path.'promotion.png';
        $delete           = File::delete($file_path);
        $file             = Input::file('img_path');
        $uploadSuccess    = $file->move($path, 'promotion.png');
        $promotion->img_path = '/images/promotion/'.$id.'/promotion.png';
    }
    if (Input::hasFile('video_path')){
        $path             = public_path().'/video/promotion/'.$id.'/';
        $file_path        = $path.'promotion.mp4';
        $delete           = File::delete($file_path);
        $file             = Input::file('video_path');
        $uploadSuccess    = $file->move($path, 'promotion.mp4');
        $promotion->video_path = '/video/promotion/'.$id.'/promotion.mp4';
    }

As you can see above, we are converting whatever file we get to a PNG with the file name promotion.png so it's easy to fetch, and we are only accepting .mp4 video format. Because of that, we don't need to worry about checking if the file exists and is it ok to overwrite it. That's why you can see in the code we delete any existing file of that name before saving.

We are two developers just doing our best, so I'm sure there is a better way of doing this. However before I refactor this whole thing, I'm hoping I can use Angular (or jQuery as a last resort) to just send the controller whatever file data Laravel needs in order to make the above code work. The answer may be as simple as "send a PUT to the method in that controller above, but instead of a normal JSON payload, use file info in this format and you can gather that info with..."

I would also appreciate any tips on better ways I can do this in the future.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2k8403S
via IFTTT