mercredi 1 novembre 2017

Implicit route, with firstOrCreate instead of findOrFail

Is it possible to create an implicit route where if it is not found the thing is created? I am using Laravel 5.5.13.

For instance this is my implicit route:

Route::post('thumbs/{player}', 'ThumbController@store');

And in my controller it is this:

public function store(Request $request, Player $player)
{
    $thumb = new Thumb($request->all());
    $player->thumbs()->save($thumb);
    return response()->json($thumb, 201);
}

So now if I go to the endpoint of ..../api/thumb/1 it will create a thumb related with Player of id 1. However instead of a id number I wanted to provide it a string like this:

..../api/thumb/PLAYER_NAME

So example of ..../api/thumb/Blagoh, then my endpoint should first find if a player exists by name "Blagoh", and if it doesn't then it should create it. I couldn't figure this one out.



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

Laravel dusk vagrant box DesiredCapabilities::__construct()

Dusk issue running Vagrant box with custom url on my mac. I had to edit DuskTestCase.php and replace http://localhost:9515 with $this->local = http://mysite.dev. $php artisan dusk tests/Browser/LoginTest.php outputs following error:

Tests\Browser\LoginTest::testLogin
TypeError: Argument 1 passed to Facebook\WebDriver\Remote\DesiredCapabilities::__construct() must be of the type array, null given, called in /Users/gmylonas/Vagrant Projects/mywebsite/vendor/facebook/webdriver/lib/Remote/RemoteWebDriver.php on line 127

/Users/gmylonas/Vagrant Projects/mywebsite/vendor/facebook/webdriver/lib/Remote/DesiredCapabilities.php:33
/Users/gmylonas/Vagrant Projects/mywebsite/vendor/facebook/webdriver/lib/Remote/RemoteWebDriver.php:127
/Users/gmylonas/Vagrant Projects/mywebsite/tests/DuskTestCase.php:46
/Users/gmylonas/Vagrant Projects/mywebsite/vendor/laravel/dusk/src/TestCase.php:210
/Users/gmylonas/Vagrant Projects/mywebsite/vendor/laravel/framework/src/Illuminate/Support/helpers.php:762
/Users/gmylonas/Vagrant Projects/mywebsite/vendor/laravel/dusk/src/TestCase.php:211
/Users/gmylonas/Vagrant Projects/mywebsite/vendor/laravel/dusk/src/TestCase.php:117
/Users/gmylonas/Vagrant Projects/mywebsite/vendor/laravel/dusk/src/TestCase.php:89
/Users/gmylonas/Vagrant Projects/mywebsite/tests/Browser/LoginTest.php:23

When I replace $this->local = http://ift.tt/h3Qi74 and $browser->visit('/')->dump(); it dumps the content of google page! $this->local = http://localhost:9515 will dump empty page

<html xmlns="http://ift.tt/lH0Osb"><head></head><body></body></html>

:question: Why it won’t work on my box url and how to solve it?

Thanks is advance.



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

Laravel image encrypt and store into db

I need user image content to be encrypted and store into database and then decrypt before display .My code in controller to encrypt,

public function savePicture(Request $request)
{
     $file = Input::file('pic');
     $img = Image::make($file);
     Response::make($img->encode('jpeg'));

     $picture = new Picture;
     $picture->name = $request->get('name');
     $picture->pic = $img;
      $picture->pic=Crypt::encrypt(file_get_contents($file));
      //dd($picture);
     $picture->save();

}

When I run this code I got the error PDOStatement::execute(): MySQL server has gone away (SQL: insert into pictures (name, pic, updated_at, created_at)... How do I solve solve this?



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

select month year and date in date field

I have the value $date='2017-10-30' in my data table I have the field requested_on has '2017-10-30 15:40:10' I want to select the row using query.My query doesn't select the row which has the $date value

$reportdate =DB::table('asset_request')
 ->where('asset_request.requested_on','=',$date)->distinct()
 ->orderby('asset_request.request_id','DESC')->get();



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

Error generating pdf from blade file in laravel 5

I am trying convert blade view to pdf. If i use normal text i am able to generate the pdf. I have few images in my blade template and with that i am not able to generate pdf.

Here is my blade template code.

<html>
<head>
  <link href="" rel="stylesheet">
</head>
<body>
  <div class="container">
    <div class="row col-md-12">
      <div class="col-md-5">
        <table>
          <tr>
            <td>ID</td>
            <td>:</td>
            <td>CO12345</td>
          </tr>
          <tr>
            <td>Date</td>
            <td>:</td>
            <td>CO12345</td>
          </tr>
          <tr>
            <td>Contract/PO #</td>
            <td>:</td>
            <td>C122</td>
          </tr>
          <tr>
            <td>Job ID</td>
            <td>:</td>
            <td>0001</td>
          </tr>
          <tr>
            <td>Client Name</td>
            <td>:</td>
            <td>Hong</td>
          </tr>
          <tr>
            <td>Project</td>
            <td>:</td>
            <td>Lake Nona Place</td>
          </tr>
          <tr>
            <td>Address</td>
            <td>:</td>
            <td>123 Roy street, Suit 107, Lake Nona, FL 32817</td>
          </tr>
        </table>
      </div>
      <div class="col-md-7">
        <img src="images/logo.jpg " class="float-right img-responsive img-thumbnail">
      </div>
    </div>
    <div class="my-auto mx-auto text-center">
      <h4>Change Order</h4>
    </div>
    <div class="row col-md-12">
      <table class="table table-bordered">
        <thead>
          <tr>
            <td><b><p class="text-md-center">Line</p></b></td>
            <td><b><p class="text-md-center">Title</p></b></td>
            <td><b><p class="text-md-center">Description</p></b></td>
            <td><b><p class="text-md-center">Total</p></b></td>
          </tr>
        </thead>
        <body>
          <tr>
            <td><p class="text-md-center">1</p></td>
            <td><p class="text-md-center">B12, Unit 114</p></td>
            <td><p class="text-md-center">Replace damage carpate in master bedroom.</p></td>
            <td><p class="text-md-center">$250</p></td>
          </tr>
          <tr>
            <td colspan="3"></td>
            <td><p class="text-md-center">$250</p></td>
          </tr>
        </body>
      </table>
    </div>
    <hr/>
    <div class="col-md-12 row">
      <div class="col-md-3">
        <img src="images/logo.jpg " class="float-right img-responsive img-thumbnail">
      </div>
      <div class="col-md-3">
        <img src="images/logo.jpg " class="float-right img-responsive img-thumbnail">
      </div>
      <div class="col-md-3">
        <img src="images/logo.jpg " class="float-right img-responsive img-thumbnail">
      </div>
      <div class="col-md-3">
        <img src="images/logo.jpg " class="float-right img-responsive img-thumbnail">
      </div>
    </div>
    <hr/>
    <div class="my-auto">
      <p>
        I hereby authorize <b>John</b> to perform the extra work listed above. I further state that I am authorized to
        approve this extra work and that my signature below serves as a payment commitment of such.
       </p>
    </div>
  </div>

   <script src="http://ift.tt/1XwG72U"></script>
   <script src=""></script>
</body>
<html>

Here is code snippet from controller class which generates pdf.

public function generatePdf(){
  $pdf = PDF::loadView('template1');
  return $pdf->download('template1.pdf');
}

I am using this http://ift.tt/TMipBv for pdf.



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

Laravel collection order similar to DB FIELD

I have a query with following order

$query->orderByRaw("FIELD(type, 'red', 'green', 'aqua') ASC");

This will order items not alphabetically, but specifically by the value.

Is there is a way to do same thing in Laravel collection?

Like:

$collection = collect(`Items from DB`);

$final = $collection->orderBy(function($item){
    return $item->color == 'red'
});



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

Connection could not be established with host on custom server

i am using laravel 5.1 & i am trying to send email after login but it show me error

Connection Could not be established with host mail.jobnow.com.sg

also try another host like gmail and other still same problem


How can i fix this



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