Support the ongoing development of Laravel.io →
posted 8 years ago
Database

I make 2 table inside up function. I can access groups table. But how can I retrieve group_details table from create_group function?

public function up()
{
    Schema::create('groups', function (Blueprint $table) {
        $table->increments('id');
        $table->string('email');
        $table->string('group_id');
        $table->timestamps();
    });

    Schema::create('group_details', function (Blueprint $table) {
        $table->increments('id');
        $table->string('group_id');
        $table->string('members');
        $table->string('total_balance');
        $table->string('cost');
        $table->string('deposite');
        $table->string('meal');
        $table->string('meal_helper');
        $table->timestamps();
    });

public function down()
{
    Schema::dropIfExists('groups');
    Schema::dropIfExists('group_details');
}

public function create_group(Request $request){

	$groupname = $request['group_name'];
	$email = $request['email'];

    
	$groups = new Groups();
	$groups->group_id = $groupname . "-".$email;
	$groups->email = $email;


    $group_details = new Groups();
    $group_details->group_id = $groupname . "-".$email;
    $group_details->members = '[]';
    $group_details->total_balance = '7000';
    $group_details->cost = '[]';
    $group_details->deposite = '4000';
    $group_details->meal = '[]';
    $group_details->meal_helper = '[]';


	$message = "Group creation fail!";
	if($groups->save()&& $group_details->save()){
		$message = 'Group Created success!';
	}
	return redirect()->route('profile')->with(['message'=> $message]);
}
Last updated 2 years ago.
0

have you created a GroupDetail model ?

0

Sign in to participate in this thread!

Eventy

Your banner here too?

sajibremix sajibremix Joined 19 Jan 2017

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.