Support the ongoing development of Laravel.io →
Database Eloquent Forms

How can I retrieve the data of specific id without using the id as url? Thank you in advance!

I mean this code(how can I make my code from below be like this):

{{ Auth::user()->name }}

this code I want to enhance:

Routes:

Route::get('/user_list',array('as'=>'UserList','uses'=>'UserController@index'));
Route::get('/user_edit/{id}',array('as'=>'UserEdit','uses'=>'UserController@edit'));
Route::post('/user_edit/{id}',array('as'=>'UserUpdate','uses'=>'UserController@update'));

Controller:

    public function index(Request $request)
    {
        $blade = [];
        $datas = UserList::whereRaw('created_at IS NOT NULL');
        if(!empty(Input::get('name'))){
            $datas = $datas->whereRaw('`name` LIKE "%' . Input::get('name') . '%"');
        }
        $datas = $datas->get();
        $blade['list'] = $datas;

    	return view('user.list')->with('datas', $datas);
    }

        public function edit($id)
    {
    	$datas = UserList::find($id);
        return view('user.edit')->with('datas', $datas);
    }

    public function update($id)
	{	
	    $datas = UserList::find($id);
	    $datas->name = Input::get('name');
            $datas->email = Input::get('email');
            $datas->admin = Input::get('admin');
	    $datas->save();
		
	    return redirect()->action('UserController@index');
	}

View:

<table class="table">
   <thead>
	<th>...</th>
	<th>ID</th>
	<th>Name</th>
	<th>Email</th>
	<th>Date Created</th>
	<th>Type</th>
	<th>Action</th>
    </thead>

    <tbody>
	@foreach($datas AS $data)
		<form method="GET" action="{{ URL::to('checkdel/' . $data->id) }}">
		<tr>
			<td><input type="checkbox" name="checkbox[]" data-id="checkbox" class="cb" value="{{$data->id}}" /></td>
			<td>{{ $data->id }}</td>
			<td>{{ $data->name }}</td>
			<td>{{ $data->email }}</td>
			<td>{{ $data->created_at }}</td>
			<td>{{ $data->admin }}</td>
			<td>
			<a href="{{ URL::to('user_edit/' . $data->id) }}">Edit</a>
			</td>
		</tr>
	@endforeach
		<p><label><input type="checkbox" id="checkAll"/> Check all</label>
		<input name='checkbox' type="submit" value="Delete"/></p>
	</tbody>
</table>
Last updated 3 years ago.
0

It's not entirely clear what you are trying to ask. Could you provide some better clarity or detail?

Also, it is possible to use something besides the ID for retrieving record data, however it really needs to be unique like a non-duplicate slug. Otherwise you will pull multiple records or be ignoring one.

Review route model binding for details on using an alternate field: https://laravel.com/docs/5.2/routing#route-model-binding

0

Sign in to participate in this thread!

PHPverse

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.