dimanche 26 avril 2020

How to get text Strings order in Laravel project

I would like to sort column like orderBy.

'WC' columns has such data

'AB-1' 'AB-2' 'AB-5' 'AB-300' 'AB-1980' .... etc

Front of "AB-" letter is same. then comes number.

Could you teach me how to write code please?

 public function index()
    {
        $images = ImageGallery::orderBy('wc', 'asc')->get();
        return view('image-gallery',compact('images'));
    }


via Chebli Mohamed

samedi 25 avril 2020

How to give order query when using scorp

I'm trying to get image data. giving order by id desc. I add orderBy sentece after get() it didn't work. Could you teach me how to add order query when using :: scope?

public function index()
    {
        $images = ImageGallery::get()->orderBy('id', 'desc');
        return view('image-gallery',compact('images'));
    }


via Chebli Mohamed

Laravel dynamic routing for search

I would like to generate dynamic route when user clicks on Search button.

I know it can be done with following GET method

https://laravel.dev/search?q=parameter 
https://laravel.dev/search?state=XYZ&category=Automobile

But instead I would like to do following

https://laravel.dev/search/state/XYZ/category/Automobile

So if I add an extra parameter in search form it will just add onto the URL.

The parameters may be optional so can not add a fix route in routes. User may supply category or may not.

How can I achieve that?

Thank you



via Chebli Mohamed

How to return an OUT/INOUT parameter using Laravel + PostgreSQL?

I am using PostgreSQL and Laravel 5 and I could find any resource explaining how to recover the output parameters from DB::statement call of a procedure in PostgreSQL.

I saw people setting cursors.. but is that the only way?

Is that so hard?



via Chebli Mohamed

How to update many db setting values in laravel

1.I have checkboxes data from view.

$data =["name1" =>"value1","name2"=>"value2","name3"=>"value3"]

2.I need to update in controller something like:

Config::update(
          ['id'=>1,"name"=>"name1","value"=>"value1"],
          ['id'=>2,"name"=>"name2","value"=>"value2"],
          ['id'=>3,"name"=>"name2","value"=>"value3"],
       );


via Chebli Mohamed

How to pass optional ID to Laravel Controller from Route?

I want to pass an ID to my controller from Routes:

Route::get('user/{id?}', function ($id= null) {
    return $id;
});

However, I'm not sure where to put the controller name and function?

MyController@get

Laravel's documentation and other questions don't seem to be related to this issue.

What am I missing here?



via Chebli Mohamed

laravel foreach and if else loop errors both in count and variables something

code of 1st error :

@extends('layouts.app')

@section('content')
<h1> posts</h1>
@if(count($posts)>1)

@foreach($posts as $post)

<div class="well">
    <h3></h3>
</div>
@endforeach

@else
<p> no posts found</p>
@endif
@endsection

and image also attached . [enter image description here][1] after i follow the instructions of the chrome this occurs and code will be .. even i have removed the @ and try if() like this .. code 2 ; @extends('layouts.app')

@section('content')
<h1> posts</h1>
@if(count($posts ?? '')>1)

@foreach($posts ?? '' as $post)

<div class="well">
    <h3></h3>
</div>
@endforeach

@else
<p> no posts found</p>
@endif
@endsection

enter image description here

[1]: https://i.stack.imenter code heregur.com/21weC.png



via Chebli Mohamed