Iam new with Laravel trying to add user type in register blade page as drop down from my database but it give me every time the same error Undefined variable: uTypes (View: /Applications/MAMP/htdocs/creativeapp/resources/views/auth/register.blade.php)
The Route code web.php:
Route::get('/auth/register', 'UsersController@index');
The controller code UsersController.php:
<?php
namespace App\Http\Controllers;
use Illuminate\Support\Facades\DB;
class UsersController extends Controller {
public function index() {
$uTypes = DB::table('userstype')->pluck("type_name", "id");
return view('auth.register', ['uTypes' => $uTypes]);
}
}
The view code register.blade.php:
<div class="form-group row">
<label for="usertype" class="col-md-4 col-form-label text-md-right">{{ __('User Type') }}</label>
<div class="col-md-6">
<select name="userType" class="form-control">
<option value="">--Select Type--</option>
@foreach ($uTypes as $ut => $value)
<option value="{{ $ut }}"> {{ $value }}</option>
@endforeach
</select>
</div>
</div>
$uTypes
as['uTypes' => ['Type 1' => 1, 'type2' => 2]]
. But this behavior is weird. Also try clearing cache and views withphp artisan view:clear
andphp artisan cache:clear
. – KeitelDOGDB::table('userstype')->pluck("type_name", "id")
actually returns something ? – Clément Rigo