dimanche 1 janvier 2017

Fatal error: Class 'Dotenv\Dotenv' not found in .../Bootstrap/DetectEnvironment.php on line 24

Not sure why i am getting this message:

Fatal error: Uncaught Symfony\Component\Debug\Exception\FatalThrowableError: Class 'Dotenv\Dotenv' not found in /home/vagrant/devbox/devbox.local/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/DetectEnvironment.php on line 24

Below is the DetectEnvironment.php code:

<?php

namespace Illuminate\Foundation\Bootstrap;

use Dotenv\Dotenv;
use Dotenv\Exception\InvalidPathException;
use Symfony\Component\Console\Input\ArgvInput;
use Illuminate\Contracts\Foundation\Application;

class DetectEnvironment
{
    /**
     * Bootstrap the given application.
     *
     * @param  \Illuminate\Contracts\Foundation\Application  $app
     * @return void
     */
    public function bootstrap(Application $app)
    {
        if (! $app->configurationIsCached()) {
            $this->checkForSpecificEnvironmentFile($app);

            try {
                (new Dotenv($app->environmentPath(), $app->environmentFile()))->load();
            } catch (InvalidPathException $e) {
                //
            }
        }
    }

My project had been working correctly until I restarted the computer and server. Whenever I go to the site or run a composer or artisan command I get the error above.

I have tried various solutions that I have found but none have worked. This includes:

  • specifically adding vlucas/phpdotenv to the composer file (it already existed in the vendor file structure, but added it to make sure)
  • running composer update and composer dumpautoload
  • creating a new .env file

Creating a new laravel project works, but I really don't want to have to do that (there must be an easy explanation/fix for this).

Similar issues as listed in, but neither have answers that work for me:

I am using the latest Laravel version and running it on Homestead.

Any guidance is greatly appreciated!



via Chebli Mohamed

onclick event only work on first child (laravel foreach)

i make button action on every data from table row. every row produce using foreach laravel blade template. the event will trigger a javascript action to delete data. but on my case the button only work on first row data. here my Javascript and html code :

function hapusFaskes(kode){
        var kodeStr = kode.toString();
        var mes = confirm('Yakin Faskesnya mau di Hapus?');
        alert(kode);
        if (mes == true){
            $.ajax({
                headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},
                url:''+'/'+kode,
                type:'get',
                success: function (r){
                    console.log(r);
                    alert(r);
                    location.reload();
                }
        });
        }
    }
<tbody id="hasil-tabel">
  @foreach ($faskes as $val)
  <tr>
     <td></td>
     <td></td>
     <td></td>
     <td></td>
     <td></td>
     <td></td>
     <td>
         <a href="" class="btn btn-default" >Edit</a>
         <a href="#" type="button" onclick="hapusFaskes()" class="btn btn-default" data-toggle="modal" data-target="#modal-faskes_delete">Hapus</a>
     </td>
  </tr>
  @endforeach
</tbody>

i don't know if there are something wrong on my code, if you know something wrong, please inform me and that will be a big help for me if you know smothing wrong on my code. thanks



via Chebli Mohamed

Merge fields laravel collections

I have two Laravel collections. Mi first collection called $custom_product:

Collection {#313 ▼
  #items: array:1 [▼
    0 => array:1 [▼
      "custom_description" => "insert description here"
    ]
  ]
}

And I have my other collection called $api_product:

Collection {#311 ▼
  #items: array:29 [▼
    "article_id" => 5570
    "active" => null
    "name" => "CORBATA POLIESTER"
    "detail" => "- Pesa: 43 gr."
    "constructor_name" => "gift"
    "stock_available" => true
    "stock" => null
    "prices" => array:6 [▶]
    "price_pvp" => 29.0
    "size" => "1410X100"
  ]
}

I want this result. The same collection but with the field custom_description added:

Collection {#311 ▼
  #items: array:29 [▼
    "article_id" => 5570
    "active" => null
    "custom_description" => "insert description here"//add this field
    "name" => "CORBATA POLIESTER"
    "detail" => "- Pesa: 43 gr."
    "constructor_name" => "gift"
    "stock_available" => true
    "stock" => null
    "prices" => array:6 [▶]
    "price_pvp" => 29.0
    "size" => "1410X100"
  ]
}



via Chebli Mohamed

How does check of authentication work in laravel?

I have the following line of code in my controller:

public function __construct() {
      $this->middleware('auth');
}

So basically what this line of code does is it checks before any method in the controller is run that the user is authenticated , I have a little confusion about this line of code though , what i want to know is where is this property middleware coming form ?? and how does this this method middleware really get included into my controller ??

Thank you.



via Chebli Mohamed

Unexepected error in laravel method when index method is called

I have the following code in my Notices controller:

public function index() {
        $notices = Notice::all();
        return view('notices.index' , compact('notices'));
}

Now as soon as i get the route that calls the index method in my controller i get the following error:

enter image description here

Why am i getting this semi-colon error ??

Thank you.



via Chebli Mohamed

Uncaught TypeError: $(...).fullCalendar is not a function(…)

$(document).ready(function() {

    // page is now ready, initialize the calendar...

    $('#calendar').fullCalendar({
        // put your options and callbacks here
        left:   'Calendar',
        center: '',
        right:  'today prev,next'
    })

});
<html>
  <head>
    <script src='http://ift.tt/2eBd7UN'></script>
<script src='/js/fullcalendar/lib/moment.min.js'></script>
<script src='http://ift.tt/2iCTAWc'></script>
<link rel='stylesheet' href='/js/fullcalendar/fullcalendar.css' />
    </head>
  <body>
  <div id='calendar'></div>
  </body>

  </html>

I am trying to add calendar with my blade template and I end up with this error.

app.js:3 Uncaught TypeError: $(...).fullCalendar is not a function(…)

my head section looks like this

<script src='http://ift.tt/2eBd7UN'></script>
<script src='/js/fullcalendar/lib/moment.min.js'></script>
<script src='http://ift.tt/2iCTAWc'></script>
<link rel='stylesheet' href='/js/fullcalendar/fullcalendar.css' />

and than after that I am calling fullCalender on ready event

<script>
$(document).ready(function() {

    // page is now ready, initialize the calendar...

    $('#calendar').fullCalendar({
        // put your options and callbacks here
    })

});
</script>

With CDN I am trying to fetch latest Jquery and FullCalendar.

With my snippet i have added /lib/moment.min.js I confirm that this file loads fine from my local machine.



via Chebli Mohamed

Search engine query impoving Laravel 5.2

Hello everyone and happy new year! So I implemented a simple search engine for my application, so the users can search for products and buy what they like. Up until now, the queries focus on only 2 columns; title and description.

This is my query:

Product::where('title', 'LIKE', "%{$query}%")->orWhere('description', 'LIKE', "%{$query}%")->get();

This is the products table which is being queried:

Schema::create('products', function (Blueprint $table) {
        $table->increments('id');
        $table->timestamps();
        $table->string('imagePath');
        $table->string('title');
        $table->text('description');
        $table->string('category',30);
        $table->integer('price');
        $table->integer('quantity');
        $table->integer('XS');
        $table->integer('S');
        $table->integer('M');
        $table->integer('L');
        $table->integer('XL');
        $table->integer('XXL');
    });

I can modify my query like this:

Product::where('title', 'LIKE', "%{$query}%")->
orWhere('description', 'LIKE', "%{$query}%")->
orWhere('category', 'LIKE', "%{$query}%")->
orWhere('price', 'LIKE', "%{$query}%")->
orWhere('quantity', 'LIKE', "%{$query}%")->
orWhere('XS', 'LIKE', "%{$query}%")->
orWhere('S', 'LIKE', "%{$query}%")->
orWhere('M', 'LIKE', "%{$query}%")->
orWhere('L', 'LIKE', "%{$query}%")->
orWhere('XL', 'LIKE', "%{$query}%")->
orWhere('XXL', 'LIKE', "%{$query}%")->get();

Now my concern lies on 2 things; How can I make the query distinguish whether a user is searching for a product with a name that contains xl in the name or a product eg a t-shirt which is xl size?

Also if a user hits the spacebar in search field (_), it returns all products in database. If a user hits the spacebar twice (__), it returns a message "there are no such products etc", like it should. Is there any way to prevent that?

Any help would be really appreciated!



via Chebli Mohamed