I have read other post regarding 404, but solution is not available for my case
I am registering a user for newsletter in website so in web.php
// FrontEnd
Route::post('store/newsletter','FrontController@StoreNewsletter')->name('store.newsletter');
in index.blade.php in below
<form action=" " method="post" class="newsletter_form">
@csrf
<input type="email" class="newsletter_input" required="required"
placeholder="Enter your email address" name="email">
<button class="newsletter_button" type="submit">Subscribe</button>
</form>
I even tried changing button to input in form
this is FrontController.php which is in app/Http/Controller/
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use DB;
class FrontController extends Controller
{
public function __construct(){
echo 'in frontend controller ';
}
public function StoreNewsletter(Request $request){
echo 'in frontend controller method';
$validateData = $request->validate([
'email' => 'required|unique:newsletters|max:55',
]);
$data = array();
$data['email'] = $request->email ;
DB::table('newsletters')->insert($data);
$notification = array(
'messege' => 'Thanks For Subscribing',
'alert-type' => 'success'
);
return Redirect()->back()->with($notification);
}
}
This __construct i have put after error for debug purposes
This is my table name
Schema::create('newsletters', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('email');
$table->timestamps();
});
Aucun commentaire:
Enregistrer un commentaire