Active Inactive user status

In this tutorial, we are going to learn how to create active inactive product status.

 

Step 1 : Open your dashboard view file (successlogin.blade.php) and there we will write the code that if the status of the product is one then it becomes active or else it becomes inactive.

<?php if($product->status == '1'){ ?> 

  <a href="#" class="btn btn-success">Active</a>

<?php }else{ ?> 

  <a href="#" class="btn btn-danger">Inactive</a>

<?php } ?>

 

Now, Create a link of status button for update product status and then pass product id with link. So that we will update the product status.

<a href="{{url('/status-update',$product->id)}}" class="btn btn-success">Active</a>

 

Step 2 : Now create a route in web.php to update product status.

Route::get('/status-update/{id}','MainController@status_update');

 

Step 3 :  In Main Controller, we will create status_update() function. So that we will update the product status in database with the help of product ID.

function status_update($id)
{
	//get product status with the help of product ID
	$product = DB::table('product')
				->select('status')
				->where('id','=',$id)
				->first();

	//Check user status
	if($product->status == '1'){
		$status = '0';
	}else{
		$status = '1';
	}

	//update product status
	$values = array('status' => $status );
	DB::table('product')->where('id',$id)->update($values);

	session()->flash('msg','Product status has been updated successfully.');
	return redirect('main/successlogin');
}

 


Result :

Source Code:

Small Laravel Project

In this project. We are providing you, how to create small project in Laravel....

Source Code