lundi 29 mai 2017

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



via Chebli Mohamed

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



via Chebli Mohamed

Laravel how to check validate unique table two field

I have tableA that there are 2 field

1. song_id
2. playlist_id

I want to check laravel validate unique func example: I have inserted data

id =>  1
song_id => 2
playlist_id => 34

then I have to insert data again I want to check that if playlist_id => 34 already inserted song_id = 2 show message "already insert" but if playlist_id => 34 insert song_id = 3 allow insert

thank you for your help!



via Chebli Mohamed

laravel many to many relation additional foreign key.?

i'm trying to get extra column as foreign key in laravel many to many relationship..here is my table structure

idcards 
   id,
   name,
quality
   id,
   name
idcard_quality
  id,
  idcard_id
  quality_id
  related_id

in above idcard_quality table i want add extra foreign key related_id, i wanted to retrieve result like every idcard hasmany qualities and that quality is another idcard.. suppose one idcardcard has one normal quality and that normal quality is different idcard... please help me



via Chebli Mohamed

Can't include internal JS file in Laravel 5

I have a simple .blade.php view for a Laravel application, I'm trying to include a JS file, which is in /public/js directory in my project.

<!DOCTYPE HTML>
<script src="http://ift.tt/1JDUibz"></script>
<script type="text/javascript" src=""></script>
<html>
    <body>
        <div id="chart-1" style="height: 300px"></div>
        <script>
            new Chartkick.LineChart("chart-1", {"2013-02-10 00:00:00 -0800": 11, "2013-02-11 00:00:00 -0800": 6})
        </script>
    </body>
</html>

It looks like this, but when I try to display this I get

test:8 Uncaught ReferenceError: Chartkick is not defined
    at test:8

In Chrome developer console, the JS file doesn't seems to be properly included in my project. Why?

Thanks for helping.



via Chebli Mohamed

Does Laravel Framework instantiate every model class at boot?

With, where, hasMany etc. methods of Eloquent class are not static.

However we call these functions like that:

// Post is a child of Model class.
Post::where(...); // we don't use New keyword.

So, does Laravel Framework initiate all Model instances before we call their methods?



via Chebli Mohamed

How to Call/Display Foreach Loop after Login

I had problem on calling page inside Foreach Loop.Although It is Okay before I click Login, but when I'd try to login,only the html tag where loaded and foreach loop cannot... On my HomeController extends Controller

public function index()
{
    return view('pages.welcome');
}

on where I call welcome page. and inside of it which is foreach loop.

  <div class="row">
    <div class="col-md-8">
      @foreach ($posts as $post)
            <div class="post">
              <h3></h3>
              <p>
              </p>
        <a href="" class="btn btn-primary btn-sm">Read More...</a>
            </div>
        <hr>
      @endforeach
    </div>
 </div>      

And I think the problem is my route:

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



via Chebli Mohamed