mardi 31 juillet 2018

Boolean not set to true

There are two tables "Stock" and "Soldstock".

Table stock contains all the stocks that have been added. Im trying to add the stocks that are sold to the SoldStock table. the stock table is shown below:

Schema::create('stocks', function (Blueprint $table) {            

  $table->increments('tag_no');   
  $table->boolean('sold')->default(0);           
  $table->integer('user_id')->unsigned();
  $table->foreign('user_id')->references('id')->on('users');
  $table->timestamps();            
});

So when i add the stocks to SoldStock table .. im trying to find that stock with that tag_no and change its sold boolean to true. But its not working! Below is the store function.

public function store(Request $request)
{

        if(Auth::check()){
            if (SoldStock::where('tag_no','=',$request->input('tag_no'))->exists()) { 
                return back()->withInput()->with('errors', 'Tag number already entered!');                
                }      

            $soldstock = SoldStock::create([
                'tag_no' => $request->input('tag_no'),                
                'user_id' => Auth::user()->id
            ]);               

            $stock = Stock::where('tag_no','=',$request->input('tag_no'))->first();            
            if($stock){
                $stock->sold=1;        
                error_log($sell->sold);                           
                return redirect()->route('soldstock.index', ['stocks'=> $soldstock->tag_no])
                ->with('success' , 'Stock added successfully');
            }                
        }        
        return back()->withInput()->with('errors', 'Error adding Stock');     
    }

I use this to find the stock:

$stock = Stock::where('tag_no','=',$request->input('tag_no'))->first();

and to change its sold boolean to true i use this:

$stock->sold=1; 

But its not working.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire