Flex
1 year ago
116
13
Laravel

How to display table row records acording to its depending values?

Posted 1 year ago by Flex

Hi, I am working with Laravel 5.6 and mysql database. In My application I have table as vehicles like this,

id  name    category    adtype     created_at             updated_at  
1   hyu     car         1           2018-09-10      2018-09-10
2   hgy     van         0               2018-09-10      2018-09-10
3   jui     car         0           2018-09-11      2018-09-11
4   frt     truck       1           2018-09-12      2018-09-12
5   hgy     van         0           2018-09-12      2018-09-12
6   gyh     car         1           2018-09-14      2018-09-14
7   hgy     truck       0           2018-09-14      2018-09-14
etc

now in My VehicleController I am showing above table data using following index

public function index()
    {
       $vehicles = Vehicle::with('uploads')->get();
       
        return view('vehicles.index')->withVehicles($vehicles);
    }

uploads is images related table to the vehicle.

this is working fine. but now I need little bit change of the system. that means I need check values of the adtype columns and if its values 1 those records should showing top of the pages according to the updated_at columns values (latest updated records should top of the page) and if the values **0** it is should display according to the created_at values of the columns (descending order of the id) (simply adtype values 1 shold top of the page and adtype 0 under the 1 values records) how can do this?

My adtype column data type is boolean

Please sign in or create an account to participate in this conversation.