0
votes

I'm having a problem with a POST, when I try to run the page and data is loaded in the database table I'm trying to read I always get a Route [MAILFP_Tree] not defined error.

The code is triggered by a call for the route in the blade file that will visualize the page

<form action="{{route('MAILFP_Tree')}}" method="post">

the routes are the following

Route::get('FP_Tree', 'HomeController@toFP_Tree')->middleware('auth');
Route::post('FP_Tree', 'MailController@toFP_Tree')->middleware('auth')->name('MAILFP_Tree');

This is the controller created for the post method (it's the one called mailController)

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use \Illuminate\Support\Facades\Mail;
use App\Mail\emailFP_TreeRow;
use DB;
use Auth;
use App\AssociationHistorical;

class MailController extends Controller
{
    public function toFP_Tree(Request $request)
    {
        $order_number = $request->input('order_number');
        $customer_name = $request->input('customer_name');
        $date_order_placed = $request->input('date_order_placed');
        $item_number = $request->input('item_number');
        $quantity = $request->input('quantity');
        $item_description = $request->input('item_description');

        $passed = array($order_number, $customer_name, $date_order_placed, $item_number, $quantity, $item_description);

        Mail::to(Auth::user()->email)->send(new emailFP_TreeRow($passed));

        //passes data to blade
        $rows = AssociationHistorical::all();
        return view('FP_Tree',[
            'rows'=>$rows
        ]);

    }
}

this is the content of the homecontroller

 public function toFP_Tree()
    {
        //passes data to blade
        $rows = AssociationHistorical::all();
        return view('FP_Tree',[
            'rows'=>$rows
        ]);
    }

This is my migration table

    Schema::create('association_historical', function (Blueprint $table) {
        $table->id();
        $table->string('order_number');
        $table->string('item_number');
        $table->string('item_description');
        $table->date('date_order_placed');
        $table->string('customer_name')->nullable();
        $table->string('sales_rep_email');

    });

The thing is that the problem happens when there is data in the association_historical table, most likely It is related to the fact that if there is no data in the database it won't run the post method, but i thought that it would make sense to show the database table...

the strange thing is that on someone else computer this works without any problem.

This is the result from PHP artisan route:list

+--------+----------+--------------------+-----------------------------+----------------------------------------------------------+------------+ | Domain | Method | URI | Name | Action | Middleware | +--------+----------+--------------------+-----------------------------+----------------------------------------------------------+------------+ | | GET|HEAD | / | generated::UYk0LlF0PlICNJsK | App\Http\Controllers\LoginPageController@showLogin | web |

| | POST | / | login | App\Http\Controllers\LoginPageController@doLogin | web |

| | GET|HEAD | FP_Tree | generated::98bieUMU1hfvx1TH | App\Http\Controllers\HomeController@toFP_Tree | web |

| | | | | | auth | | | GET|HEAD | Prediction | generated::4HdessOBvQL3KmpT | App\Http\Controllers\HomeController@toPrediction | web |

| | | | | | auth |

| | GET|HEAD | PredictionsLanding | generated::Xtf7I1MCKtlOSX3Y | App\Http\Controllers\HomeController@toPredictionsLanding | web |

| | | | | | auth |

| | GET|HEAD | UserManagement | generated::aOYFVG9JOLTfGjB5 | App\Http\Controllers\HomeController@toUserManagement | web |

| | | | | | auth |

| | GET|HEAD | api/user | generated::3SA9mFdg4RMncH1a | Closure | api |

| | | | | | auth:api | | | GET|HEAD | logout | generated::YeCPB1fIxlH8JqDe | App\Http\Controllers\HomeController@doLogout | web |

| | | | | | auth | +--------+----------+--------------------+-----------------------------+----------------------------------------------------------+------------+

1
You may have routes cached, try php artisan route:clear.DigitalDrifter
I feel like an idiot. it did fix it. Thank you very very much!Danilo Patrucco

1 Answers

0
votes

it was so simple, thanks DigitalDrifter, just had to do a php artisan route:clear