jeudi 23 août 2018

Laravel sort by keys

I make an array with collections with code:

$hours = Voucher::where('created_at','>=', Carbon::now()->startOfMonth())->get()->groupBy(function($item)
{
  return $item->created_at->format('H');
});

dd($hours);

so I get data like this:

enter image description here

SO keys are hours (00-23).

How I can arrange it starting by 00, 01, 02, 03 ... ...



via Chebli Mohamed

mercredi 22 août 2018

How to run Laravel 5.3 ..?

i am using laravel 5.3, How to run welcome message

this is my web.php file

<?php
  Route::get('/', function () {
  return view('welcome');

});



via Chebli Mohamed

lundi 20 août 2018

why jpg file are saved as tmp in laravel 5.1

OK i'm new in Laravel and i need any help in my code. I'm trying to upload image in admin panel. but this image is uploading as tmp. Need i add something other code in my code?

public function store(Request $request)
{


    if ($request->hasFile('contents')) {


        $destinationPath = 'pictures/SliderImages';
        $files = $request->contents;
        $file_name = $files->getClientOriginalName();
        $files->move($destinationPath, $file_name);
        echo "Complete";
    } else {
        echo "No File";
    }


    $inputs = $request->all();

    $sliders = Sliders::Create($inputs);

    return redirect()->action('SliderController@index');
}

this is my blade

                @foreach($sliders as $slider)
                    <tr>
                <td></td>
                <td></td>
                <td><img src=""></td>
                    </tr>
                    @endforeach

this is result in phpmyadmin



via Chebli Mohamed

how to integrate wecashup payment in laravel5.1?

i want to integrate wecashup payment in my laravel5.1 project. I used https://www.wecashup.com , https://www.wecashup.com/dashboard/settings , https://www.wecashup.com/tutorials for this.



via Chebli Mohamed

mardi 14 août 2018

Best way to check if model returns results in laravel

I'm fairly new to laravel and looking for the best method for checking whether a model has returned any results or not.

The example below will return null if not results are found. Which is perfect if you only ever want the first result.

$results = FooBar::where(['col' => 'someVal', 'col3' => 'value'])->first();

The example below will return an object regardless of there being any results.

$results = FooBar::where(['col' => 'someVal', 'col3' => 'value'])->get();

Therefore i'm currently having to do this every time:

if($results && count($results)) {
     // then do stuff
}

I have methods that call various models and the code looks ugly and inefficient with all of these count() functions.

FYI I'm currently using laravel 5.1 due to our php version (not within my control).



via Chebli Mohamed