lundi 29 mai 2017

paginate find if data returned is empty laravel 5.4 and display custom message

I recently added pagination in Laravel project. so I receive json data like this:

{"per_page":1,"current_page":1,"next_page_url":null,"prev_page_url":null,"from":null,"to":null,"data":[]}

before I use to get []

so my if condition use to be

@if($send_requests == '[]')

How can I check if data is empty in above json ?

I tried:

@if($send_requests->data == '[]')

it does not seem to work like that.



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

Laravel 5 how to handle redirect when login with facebook / google on API?

When use Laravel Socialite package to login, there has an official method redirectToProvider

public function redirectToProvider('facebook')
{
  return Socialite::driver('facebook')->redirect();
}

If it serves as API, e.g, the route is /api/login/facebook, the response will have error Session store not set on request.

So how to send login request to provider when it is on API?



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

How to store images for android/ios backend

I am trying to implement an api for my dummy mobile app and I am using MySQL and Laravel 5 for that. I want to store images that user posts from mobile client. I wonder, what is the best practice for storing this images. Any help would be appreciated.



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

delete a user post using ajax and js in laravel 5.4

I'm new to Laravel. I am trying to create a common social network, Now i want to delete a user's post, After hitting the form it loads the ajax but can not delete the data. Here I gave my code. /My ajax code is:/

`$("#_global_modal").delegate('#modal_form_delete', 'submit', 
 function(event) 
 {

    // To stop a form default behaviour
    event.preventDefault();

    $.ajax({ 
       url: $(this).attr('action'),               
       type: $(this).attr('method'), 
       dataType: 'json',
       data: $(this).serialize(),
   })
    .done(function(response){
        if(response.delete == "success"){
            window.location.href = response.redirect_route
        }else{
            console.log(response);
        }
    })
    .fail(function(){
        console.log("error");
    })
    .always(function(){
        console.log("complete");
    });

});`

/*Route:*/
`Route::post('delete','crude@delete')->name('delete');`


/*
    `route_user_post        =   "";
    route_delete_post   =   "";`
*/

 /*My controller part:*/

 `public function delete(Request $request)

 {
    if($request->ajax()){
       $user = Auth::user();
       $user->post()->delete(['post' => $request->post]);

       return response()->json([
                'delete'            =>  'success',
                'redirect_route'    =>  route('profile')
            ]);

    }else{
        return response()->json([
            'delete'            =>  'ERROR',
            'ERROR_MSG'    =>  'ERROR MSG'
        ]);
        dd("Sorry you have to send your form information by using ajax 
      request");
    }
 }`

 /*So how can I solve this problem?*/



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

laravel controller cannot use currentRouteName() inside construce()

I have named routes:
admin.post.category
admin.post.tag
admin.post.theme

routes\admin.php

Route::group(['prefix' => 'post', 'as' => 'post.'], function () {
    Route::resource('category', 'Admin\Post\TermsController');
    Route::resource('theme', 'Admin\Post\TermsController');
    Route::resource('tag', 'Admin\Post\TermsController');
});

Http\Controller\Admin\Post\TermsController

public function __construct(Request $request)
{
    $this->request = $request;

    $route_name = Route::currentRouteName();
    $arr = explode('.', $route_name);
    echo "<pre>".print_r($arr[2], 1)."</pre>"; exit;

}

When I visit the page http://localhost/admin/post/category, it can show category. But when I run command

php artisan route:list

It shows

  [ErrorException]
  Undefined offset: 2

If I move the three lines from __construct() to index()

$route_name = Route::currentRouteName();
$arr = explode('.', $route_name);
echo "<pre>".print_r($arr[2], 1)."</pre>"; exit;

Then "php artisan route:list" runs well.

How to fix this?



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

Laravel 5.4 Intevention Image Not Readable Exception when the image is readable

I'm learning about the Intervention Image package with Laravel 5.4. I've got an image stored in my public/images folder.

I installed Image according to the instructions on Intervention's page: added intervention to my composer.json file, ran composer update, updated my config/app file, and ran composer dump-autoload.

  • When directly accessed as an image (the printf statement in the code block below) the image displays.

  • Using the make method, I get a NotReadableException in AbstractDecoder.php.

Does anyone see if I'm doing something wrong in the code or may have missed a step in installation?

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Intervention\Image\Facades\Image;

class TestController extends Controller
{
    public function imagetest()
    {
        printf('<img src="/images/j6.jpg">'); //correctly displays image on page

        $img = Image::make("/images/j6.jpg")->resize(300, 200); //throws the error
        return $img->response('jpg');
    }
}

And here's the lead of the error block that's on the page after the "printf" image:

Whoops, looks like something went wrong.

1/1
NotReadableException in AbstractDecoder.php line 339:
Image source not readable
in AbstractDecoder.php line 339
at AbstractDecoder->init('/images/j6.jpg') in AbstractDriver.php line 64
at AbstractDriver->init('/images/j6.jpg') in ImageManager.php line 50
at ImageManager->make('/images/j6.jpg') in Facade.php line 221
at Facade::__callStatic('make', array('/images/j6.jpg')) in TestController.php line 14
at TestController->imagetest()
at call_user_func_array(array(object(TestController), 'imagetest'), array()) in Controller.php line 55
at Controller->callAction('imagetest', array()) in ControllerDispatcher.php line 44
at ControllerDispatcher->dispatch(object(Route), object(TestController), 'imagetest') in Route.php line 203
at Route->runController() in Route.php line 160
at Route->run() in Router.php line 559
at Router->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 30
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in SubstituteBindings.php line 41
at SubstituteBindings->handle(object(Request), object(Closure)) in Pipeline.php line 148



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

Laravel app URL not working correctly when sending out mails

I have mails that get sent out using a cron on a centos box. The cron calls console/kernal.php where the function get's called to send out the mail

When sending the mail out from within a browser the urls in the mail are correct but when sending with the cron it changes the urls to localhost

I have this in my env file

APP_URL = example.com

And in my config/app.php I have this

'url' => env('APP_URL', 'example.com'),

I've done everything to book I believe. If I change the the url env var to http://example.com then the emails get sent out with the right url's but then entire site then get's redireted to http://http//example.com

What is going wrong here. Please help



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