Support the ongoing development of Laravel.io →
posted 7 years ago
Database
Last updated 1 year ago.
0
$langs = DB::table($table_name)->get();
0

@TorchSK : Thank you very much for your help. I've also used the way you provided, but I don't know how to access the data returned to the view. Could you guide me about that?

Last updated 7 years ago.
0

For access your data into view, you need just to do loop. For example:

@foreach($langs as l) <div>{!! $l->datafromdatabase !!} @endforeach

0

@jonitopsg : I tested what you adviced but there is no result seen in output ! How can I check if any data has been exploited and if it is passed to the view before being processed and shown ?

0

Have you tried to use dd($langs) on your controller?

0

Yes, and the result indicates I've not retrieved anything from the database (at least I think so). The output is :

Collection {#194 ▼
  #items: []
}

There is actually values assigned to database columns at the time of their creation and I can view them in phpmyadmin. I wonder what can be the error in my work. I have even tried the code below before passing it to the view, but still nothing is displayed :

$flattened = $langs->flatten();
Last updated 7 years ago.
0

Have you tried to access another table of your DB to show if you got something?

0

Yes, and the same happens !!

0

Are you connecting your DB to your laravel project?

0

I have set the values in .env and /config/database.php , Is it not enough? I checked the table contents by mysql from bash and

SELECT * FROM TABLE_NAME;

returns :

Empty set (0.62 sec)

while I can see the columns have values when viewed in phpmyadmin. Should I have done something after creating the table in homeController.php to make the default values saved? Considering the nature of the application (I needed to create the a table per user dynamically) I wrote the codes below to be able doing it :

$user_id = Auth::user()->id;
$user_name = Auth::user()->name;
$table_name = $user_name . '_' . $user_id;

Schema::connection('mysql')->create($table_name, function ($table){
    $value = 0;
    $table->string('langs')->default('langs');
    $table->string('en')->default($value);
    $table->string('fr')->default($value);
    $table->string('sp')->default($value);
});

$langs = DB::table($table_name)->get();
Last updated 7 years ago.
0

Just set values into the .env file. You saw the values into DB? I saw the docs of laravel and you can do the same with:

Schema::create($table_name, function ($table) { $table->increments('id'); });

0

Sign in to participate in this thread!

Eventy

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.

© 2024 Laravel.io - All rights reserved.