jeudi 2 juin 2016

Laravel 5.1 Maintenance Mode Not Working

Hi I am trying to put my Laravel 5.1 app into maintenance mode using the php artisan down command but it is not showing a maintenance page the app continues to function the same.

I can confirm that the down file is being created in storage/app/framework directory and my kernel has the \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class in the global $middleware array.

I have also tried changing the .env APP_ENV and APP_DEBUG values with no success.

If anyone can help me identify why maintenance mode isn't working it would be much appreciated.



via Chebli Mohamed

How to send push notification from web to iOS and android device using AWS SNS in Laravel 5.1?

I have coded like,

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

    $data = json_encode([
        'APNS' => ['apns' => [
                'alert' => $message
            ]
        ]
    ]);

    Log::info($data);

    $sns->publish(array(
        'Message' => $data,
        'TargetArn' => "arn:aws:sns:us-west-2:360542326270:endpoint/APNS_SANDBOX/Testtest/20a75cd1-da25-3331-8126-4db497cbdd5e"
    ));

I'am getting the error as below:

[Aws\Sns\Exception\SnsException]                                                                                                                                                        

Error executing "Publish" on "http://ift.tt/19difur"; AWS HTTP error: Client error: POST http://ift.tt/19difur resulted in a 400 Bad Request response:

  <Type>Sender</Type>                                                                                                                                                                 
  <Code>InvalidPara (truncated...)                                                                                                                                                    

InvalidParameter (client): Invalid parameter: TargetArn Reason: No endpoint found for the target arn specified -

  <Type>Sender</Type>                                                                                                                                                                 
  <Code>InvalidParameter</Code>                                                                                                                                                       
  <Message>Invalid parameter: TargetArn Reason: No endpoint found for the target arn specified</Message>                                                                              

<RequestId>18937e90-5453-5e30-bf89-315a59c3f2af</RequestId>                                                                                                                           

[GuzzleHttp\Exception\ClientException]
Client error: POST http://ift.tt/19difur resulted in a 400 Bad Request response:

  <Type>Sender</Type>                                                                             
  <Code>InvalidPara (truncated...) 

Can anyone help me to find the solution? Thanks in advance..



via Chebli Mohamed

Difference among return view(), return response()->view() and abort() in laravel

Suppose i want to return 404 error view from my controller's method and i have this block of code.

try {

        file_get_contents('http://ift.tt/1jv3Zxg');

    } 
catch (\Exception $e) {

        return view('errors.404'); // View::make('errors.404');

        // or                       

        return response()->view('errors.404'); // Response::view('errors.404');

        // or

        abort(404); // App::abort(404);

    }

Each time i'll see the same view output of 404. Here is my questions.

What is the difference among view(), response()->view() and abort()?

What is the particular use cases of them?



via Chebli Mohamed

Laravel 5.1 PHPexcel install error

I want to add class PHPExcel to my project. I use composer to add PHPExcel. I tried some command line.

php composer.phar update

or

php composer.phar require phpexcel/phpexcel

But, i alway receive error look like image: at here. And maatwebsite/excel, too.

What is wrong with my project? Please help me!



via Chebli Mohamed

mercredi 1 juin 2016

Angularjs http.delete is not working after deploying project on server

I am working on a Laravel5.1 project. While working on localhost using xampp http.delete works fine but after hosting the project on remote server this delete option is not working though other properties are working fine. here is a portion of the code

$scope.removeSaleTemp = function(id) {
        $http.delete('api/saletemp/' + id).
        success(function(data, status, headers, config) {
            $http.get('api/saletemp').success(function(data) {
                    $scope.saletemp = data;
                    });
            });
    }

'api/saletemo/' goes to SaleTempApiController

public function destroy($id)
{
    SaleTemp::destroy($id);
}

view part:

<tr ng-repeat="newsaletemp in saletemp">
                                <td>@</td><td>@</td><td>@</td><td><input type="text" style="text-align:center" autocomplete="off" name="quantity" ng-change="updateSaleTemp(newsaletemp)" ng-model="newsaletemp.quantity" size="2"></td><td>@</td><td><button class="btn btn-danger btn-xs" type="button" ng-click="removeSaleTemp(newsaletemp.id)"><span class="glyphicon glyphicon-trash" aria-hidden="true"></span></button></td>
 </tr>

Note that , This code works fine on localhost (xampp) but fails after deploying in server.



via Chebli Mohamed

Nested eager loading with constraint not working

I am having hard time using nested with with constraint. Can someone help me to group subjects based on the what semester it will be offered.

MyController

    public function show($id)
    {
        $student = Student::with(['course', 'course.curriculum', 'course.curriculum.subjects' => function($query){
            $query->groupBy('sem_offered');
        }])->findOrFail($id);

        return view('students.show', compact('student'));
    }

show.index

@foreach($student->course->curriculum->subjects['first first-sem'] as $subject)
<tr>
    <td></td>
    <td></td>
    <td></td>
    <td></td>
    <td>98</td>
</tr>
@endforeach



via Chebli Mohamed

Laravel 5.1 Session not working outside Route::get

I have some code like this and working:

Route::get('addnew',function(){         
        $user = Users::where('username','=',session('username'))->first();
        $data = $user->toArray();
        return view('layout.addnew')->with($data);
    });
Route::post('addnew', ['uses'=>'UsersController@addnew']);

With code above: session('username') not null

But, when i use this code like below:

$user = Users::where('username','=',session('username'))->first();
$data = $user->toArray();
Route::get('addnew',function() use($data){
        return view('layout.addnew')->with($data);
    });
Route::post('addnew', ['uses'=>'UsersController@addnew']);

With code above: session('username') null => so $data is non-object and code not working.

Somebody help me, please!

Thank you very much!



via Chebli Mohamed