Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

najmapaj's avatar

I am creating a like and dislike system, however when I go to the file in the browser the php doesn't execute and it just shows in the file.

Like & Dislike

Like & Dislike System

Using ajax to like and dislike system in laravel 5.5

     <div class="row">
       <div class="col-sm-8">
         <div class="blog-post">
           @foreach ($posts as $post)
        <div class="post" data-postid="{{ $post->id }}">
        <a href="#"><h3>{{$post->title}}</h3></a>
        <h6>Posted on {{$post->created_at}} by {{$post->user->name}}</h6>
         <p>{{$post->body}}</p>
         <div class="interaction">
           <a href="#">Like</a>
           <a href="#">Dislike</a>
   </div>
  </div>
 @endforeach
0 likes
24 replies
kingmaker_bgp's avatar

are you visiting the file directly?

using the File in the browser with the URL like file://<path_to_file>/file_name.blade.php ?

aswinghosh's avatar

change file name from filename.php to filename.blade.php

najmapaj's avatar

No sir i'm not i'm going to try that right now

najmapaj's avatar

so i went to the file and the php shows in the browser it excecutes like it's html

kingmaker_bgp's avatar

@aswinghosh answer makes some sense with the current level of details.

If nothing solves the Issue, please provide us with much more Details.

siangboon's avatar

it's better to screenshot, as it may misleading each others.

kingmaker_bgp's avatar

@najmapaj, I didn't told you to visit using file://.... protocol.

I asked you "whether you are doing like that?"

make sure the file is in .blade.php extension

aswinghosh's avatar

I think there must be some problem with the ajax code.

najmapaj's avatar

I have three controllers here is Controller.php:

<?php

namespace App\Http\Controllers;

use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;

class Controller extends BaseController
{
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
}

HomeController.php:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class HomeController extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('auth');
    }

    /**
     * Show the application dashboard.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        return view('home');
    }
}

PostController.php:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Post;
use App\Like;

class PostController extends Controller
   {
  public function index () {
    $posts = Post::orderBy('created_at', 'desc')->get();
    return view('post.index', ['posts' => $posts]);
  }
}
najmapaj's avatar

The index.blade.php is already there it's at the very top

najmapaj's avatar

I don't think I have that what is it exactly?

Cronix's avatar

You said you were using ajax in your first post, so he's asking to see that code. How could you not have it if you're using it?

Using ajax to like and dislike system in laravel 5.5

Please or to participate in this conversation.