0

After Click On "Yes I am Sure" button data not inserting into database Here Is my code Auth user block another user from viewing their profile. so, i am inserting data auth username and block user username into data after click on "Yes I am Sure" but data is not inserted.

my .blade file profile/index.blade.php here "Yes I am Sure" href link to go on route

<div class="cd-popup" role="alert">
  <div class="cd-popup-container"><br>
    <div class="content_block">Are you sure you want to block this person?</div><br>
   <div class="content_block_instruct">Hide content and notifications from this user.</div><br>
    <ul class="cd-buttons">

      <li> <a href="{{route('profile.index',['username' => $user->username])}}">Yes I am Sure!</a></li>

      <li><a href="">Cancled</a></li>
    </ul>
    <a href="#0" class="cd-popup-close img-replace">Close</a>
  </div> <!-- cd-popup-container -->
</div>

Route File

Route::post('/{username}', [
    'uses' => 'Profile\UserProfileController@blockUser',
    'as'   => 'profile.index',
]);

Controller file Whose username show on URL, with their username check BlockUser model if block_username and URL username same data not inserted else data not same their data inserted into database

public function blockUser(Request $request, $username)
{

       $blocked = User::where('id', Auth::user()->id)->first();
       if (blockuser::where('block_username', $username)->first()){

       }else{
           $blocked = new blockuser;
           $blocked->user_username = Auth::user()->username;
           $blocked->block_username = $username;
           $blocked->save();
       }

       $user = Auth::user();
       $userprofile = userprofile::where('user_id', Auth::user()->id)->first();
       return view('profile.index',compact('user', 'userprofile'));
 }

Here is my User Model

  public function blockuser(){
        return $this->hasOne( BlockUser::class);
  }

BlockUser Model

use App\User;

class BlockUser extends Authenticatable
{

      public $timestamps = false;

      protected $fillable = [
        'user_username', 'block_username',
      ]; 

      public function user()
      {
        return $this->belongsTo( User::class, 'username' );
      }
}

Database table block_users

id   user_username   block_username
1    
2

1 Answer 1

1

Clicking simply on link actually makes GET HTTP Request. You need to change fromRoute::post(...) to Route::get(...). If you still want to have post method, then make simple ajax call with post method on onclick event of the anchor tag.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.