using Laravel 5.6.28 my route on web.php file looks like this:
Route::get('kitysoftware/besttrades', 'SectorsController@besttradesview');
My controller with bestrasdeview function:
class SectorsController extends Controller
{
public function besttradesview()
{
$sectors = DB::table('Sectors')->get();
foreach ($sectors as $sector) {
echo $sector->SectorName;
}
//passing variable sectors1 to my view (is = $sector)
return view('besttradesview', ['sectors1' => $sector]);
}}
My view Bestradesview.blade.php is:
<form method="GET">
<div class="selectsector">
<Select class="selectsector" name = "sectors">
<option value=""></option>
<!-- test#2: <option value=""></option> -->
<!-- test#3: <option value=""></option> -->
</form>
</select>
- And i get this error: Use of undefined constant sectors1 - assumed 'sectors1' (this will throw an Error in a future version of PHP)
-
When testing #2 commented line instead i get another error: Symfony \ Component \ Debug \ Exception \ FatalErrorException (E_UNKNOWN) Cannot use [] for reading
-
When testing #3 commented line without [] i get another error: Use of undefined constant sectors1 - assumed 'sectors1' (this will throw an Error in a future version of PHP)
Probably it's pretty simple but it's driving me nuts because i can't see why the variable is not passing to the view. I know it's reading my table because if i remove the last return view call line on my controller, it echoes out all the values from my SectorName column, but i want it on a select dropdown menu.
I have been reading the docs, forums and watching laracast videos without luck. Any insight or just pointing me out to where to learn the proper sintax solution will be appreciatted. Thanks in advance
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire