Hello
I don't understand what I am doing wrong.
I am trying pass the information to api route but it redirects me to the main page.
I will give my source, maybe someone will see something:
HTML
<form method="POST" enctype="application/x-www-form-urlencoded" accept-charset="UTF-8" action="{!! route('blacklistvotes') !!}">
@method('POST')
{{ csrf_field() }}
<input type="hidden" id="vote" name="vote" value="down">
<input type="hidden" id="reportedcase" name="reportedcase" value="{{ $results->id }}">
<button type="submit" class="btn btn-danger">Remove vote</button>
</form>
API.php route:
Route::post('blvotes', ['middleware' => 'auth:api', 'uses' => 'ApiController@blacklistvotes'])->name('blacklistvotes');
ApiController.php:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Auth;
use App\Blacklist;
use App\BlacklistVotes;
class ApiController extends Controller
{
public function __construct()
{
$this->middleware('auth:api');
}
function blacklistvotes(Request $request)
{
if ($request->all())
{
$voteinput = $request->input('vote');
$reportedcaseinput = $request->input('reportedcase');
if (!empty($voteinput) && !empty($reportedcaseinput)) {
//Checking if reported case exists in the $caseexists
if($caseexists)
{
$user = Auth::id();
///Checking if a vote exists in $voteexists
if($voteinput === "up")
{
if (!$votexists)
{
///Saving details
return 'back()';
}
}
if($voteinput === "down")
{
if ($votexists)
{
//Deleting vote
return 'back()';
}
}
}
else {
return redirect('blacklist');
}
}
else {
return redirect('blacklist');
}
}
else {
return redirect('index');
}
}
}
Yeah did put in 'back()' where is the return. I hoped I will see that text just for testing.
I have this code but I am redirected to the main page when I click to the vote button.
I am logged in and I get the Auth::id() without problem so hmm it is not issue.
Someone sees a problem in the code? I am trying to solve this in these 4 days but no success.