Issue with redirect() when using conditional to evaluate multiple form buttons

Tags: php laravel-5
By : SGouws
Source: Stackoverflow.com
Question!

So I've built a small conditional to evaluate which button is pressed in my form (as there are 2). This works fine and fires off the correct method and writes the appropriate data to the DB, however my redirect is not working. It saves() to the DB and then simply stays on the page designated as the POST route.

I suspect the problem has something to do with my conditional and the use of $this.

Here is my check_submit method:

public function check_submit()
{
    if(!is_null(Input::get('add_to_invoice'))){
        $this->invoice_add_item();
    } elseif(!is_null(Input::get('complete_invoice'))) {
        $this->invoice_complete();
    }
}

Here is one of the 2 methods which I am currently testing:

public function invoice_add_item()
{
    $input = Request::all();
    $invoice_items = new Expense;
    $invoice_items->item_id = $input['item_id'];
    $invoice_items->category_id = $input['category'];
    $invoice_items->price = $input['price'];
    $invoice_items->store_id = $input['store'];

    if(Input::has('business_expense'))
    {
        $invoice_items->business_expense = 1;
    }
    else{
        $invoice_items->business_expense = 0;
    }
    $invoice_items->save();
    return redirect('/');
}

Perhaps there is a better way of handling this in my routes(web) file, but I'm not sure how to go about this.

By : SGouws


Answers

You should add the return to the check_submit() method. Something like

public function check_submit()
{
    if(!is_null(Input::get('add_to_invoice'))){
        return $this->invoice_add_item();
    } elseif(!is_null(Input::get('complete_invoice'))) {
        return $this->invoice_complete();
    }
}

Better yet, you should probably return a boolean on invoice_add_item() and based on that, redirect the user to the correct place (or with some session flash variable with an error message)

By : milz


Try with this:

var ref = firebase.database().ref().child('feeds/${vm.currentUser}');

$firebaseArray(ref);


Because your assumption is wrong. You expect new Vector3(0,0,0) and new Vector3(Screen.width, 0, 0) to be in screen space (left & right edge of screen I believe) but in fact they are in world space (Vector3(0,0,0) is the world's origin, not the edge of screen).

You can try this. Basically, this code moves your object to where you tap.

void OnMouseUp()
{
    // Cast a ray from camera through mouse position
    Ray ray = camera.ScreenPointToRay(Input.mousePosition);
    RaycastHit hitInfo;
    Physics.Raycast(ray, out hitInfo);
    // Lerp to the impact point
    transform.position = Vector3.Lerp(transform.position, hitInfo.point, 2f * Time.deltaTime);
}
By : Loop


This video can help you solving your question :)
By: admin