mardi 29 novembre 2016

Upload file in S3 using Laravel 5.3

Installation Process

I followed this tutorial to install aws Package in Laravel 5.3

My Code is below

$s3 = \App::make('aws')->createClient('s3');

$s3->putObject(array(
    'Bucket'     => 'Bucket_Name',
    'Key'        => 'AWS_ACCESS_KEY_ID',
    'SourceFile' => 'http://domainname/sample.txt',
));

I am trying a txt file with around 50 bytes contents and got below error.

A sha256 checksum could not be calculated for the provided upload body, because it was not seekable. To prevent this error you can either 1) include the ContentMD5 or ContentSHA256 parameters with your request, 2) use a seekable stream for the body, or 3) wrap the non-seekable stream in a GuzzleHttp\Psr7\CachingStream object. You should be careful though and remember that the CachingStream utilizes PHP temp streams. This means that the stream will be temporarily stored on the local disk.

Am I missing something?



via Chebli Mohamed

lundi 28 novembre 2016

Phpunit overriding variable in .env

In my .env file of a laravel 5.1 project i have set the APP_ENV to local, But when i run the test from the terminal the with

vendor/bin/phpunit

the debug and die on

dd(env(APP_ENV));

gives me "testing".

I Have dont a good research on this, tried using the following ways -

  • trying to set the APP_ENV=local pipelining vendor/bin/phpunit form the cli.
  • Trying to add env variable in the phpunit.xml file<env name="APP_ENV" value="local" override="true"> (dosent seem to override though)
  • adding a .env.testing file and setting the APP_ENV=local
  • in the testCase.php file where the application autoloads $app->loadEnvironmentFrom('.env.testing');

none of the above methods give me the expected result rather everytime i run the test give APP_ENV as "testing".

Not able to trace where is phpunit setting this variable from. Pls help out!



via Chebli Mohamed

how can i retrieve username from another collection by using join in laravel

//viewing tickets generated by them $user= Auth::user()->_id; $tickets = ticket::where(function ($query) use ($user) { $query->where('user', '=', $user); })->get();

  //  created ticket by which user
    $atickets = ticket::where(function ($query) use ($user) {
        $query->where('user_assigned', '=', $user);
    })->get();


    return view('ticketviews', compact('tickets','atickets'));

$atickets returns record details such as user_id and ticket details, now i need to display the username for that particular record stored in another collection mongodb. Can anyone suggest me the code to do that.



via Chebli Mohamed

dimanche 27 novembre 2016

Failing to install Laravel/Homestead with VirtualBox via Vagrant

I'm trying to install Laravel / Homestead with VirtualBox via Vagrant. I followed step by step the installation guide but I keep getting this error:

The box 'laravel/homestead' could not be found or
could not be accessed in the remote catalog. If this is a private
box on HashiCorp's Atlas, please verify you're logged in via
`vagrant login`. Also, please double-check the name. The expanded
URL and error message are shown below:

URL: ["http://ift.tt/1KBs0RO"]

I checked that I use latest version of Vagrant(1.8.7).



via Chebli Mohamed

samedi 26 novembre 2016

Passing data from view to controller in Laravel 5.1

i want to pass arguments from a blade view to a function in the controller

index.blade.php

<a href="" class="like">
    Like
</a>

<a href="" class="like">
    Dislike
</a>

PostController.php

  public function getLikePost($post_id, $like_value)
    {
       $post = Post::find($post_id);
       ...
    }

routes.php

Route::get('like', [
        'uses' => 'PostController@getLikePost',
        'as'   => 'like'
      ]);

but i get an error message

ErrorException in PostController.php line 149:
Missing argument 2 for App\Http\Controllers\PostController::getLikePost()

could anyone help me with this issue?



via Chebli Mohamed

Laravel, Image get from storage display correctly but console return status code 404

I'm having this problem where by image get from storage shows in page correctly but console shows status code 404 as shown in the image belowenter image description here



via Chebli Mohamed

Nearby stores in Laravel

i'm try to get neraby store in Laravel 5.1 I have geocoding parser that caluclate coorinate. But i have problem with haversine formulas. Basically i need that from table Aziende (Stores) given a lat, long e category passed trough url, fetch the nearby stores.

I try with this code:

$dove = Input::get('dove');
    $categoria_id = Input::get('id_categoria');
    // 4: check if any matches found in the database table 
    if (!empty($dove)) {
        $response = \GoogleMaps::load('geocoding')->setParamByKey ('address', $dove)->get();
        $response = json_decode($response, true);
        $latitude = $response['results'][0]['geometry']['location']['lat'];
        $longitude = $response['results'][0]['geometry']['location']['lng'];
        $radius = '5';
        $aziende  = DB::table('aziende')
            ->select(
                 ( 'lat * acos( cos( radians(50) ) * cos( radians( lat ) ) * cos( radians( lng ) - radians(-122) )
                       + sin( radians(37) ) * sin( radians( lat ) ) ) as distance') )->get();




    } else {
    $aziende = DB::table("aziende")->where('categoria', $categoria_id)->get();
 }
 ?>



via Chebli Mohamed