mohamadAbdelhady

Member Since 2 Months Ago

Experience Points
880
Total
Experience

4,120 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed
2
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start your engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-in-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • evangelist Created with Sketch.

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

  • Community Pillar

    Earned once your experience points ranks in the top 10 of all Laracasts users.

Level 1
880 XP
Jun
10
2 days ago
Activity icon

Started a new Conversation How To Use Laravel Echo With Javascript Only No Framework Like Vue

I am coding a website, but i am not using any java-script framework only java-script, i want to know how to use laravel echo with java-script file, i tried to do so but it gave me "Uncaught SyntaxError: Cannot use import statement outside a module"

May
31
1 week ago
Activity icon

Started a new Conversation 500 (Internal Server Error) On Ajax Post

I made an ajax call that supose to call a function called like on the ratesys controller, the function take the post id and then add it to the reactor table with the user id and then increment the like on the post by one

the like function

 public function like(Request $request)
    {
        $post_id=$request->input('postid');
        $check=DB::table('reactors')->where('post_id',$post_id)->where('user_id',auth()->id())
            ->value('type');
        if ($check=null)
        {
            $like=reactors::create([
                'user_id'=>auth()->id(),
                'post_id'=>$post_id,
                'type'=>'1'
            ]);
            posts::where('post_id', $post_id)
                ->update([ 'like' => DB::raw('like + 1')]);
        }
        elseif ($check=0)
        {
            reactors::where('post_id', $post_id)
                ->where('user_id', auth()->id())
                ->update(['type' => 1]);

            posts::where('post_id', $post_id)
                ->update([ 'like' => DB::raw('like - 1')]);
        }
         $reaction=DB::table('posts')->where('id',$post_id)->value('likes','dislikes')->first();
        return response()->json($reaction);
    }

my ajax call

 <script>
        $("#like_btn").click(function (e){
            e.preventDefault();

            let postid=$("#post_id").val();
            let _token = $("input[name='_token']").val();

            $.ajax({
                url:"{{route('like')}}",
                type:"POST",
                data:{
                    postid:postid,
                    _token:_token

                },
                success:function (response)
                {
                    if (response)
                    {
                        $("#like_num").innerHTML=response.like;
                        $('#dislike_num').innerHTML=response.dislike;
                    }
                }

            });
        })
    </script>

the like button

 <span  style="float: right;"><a href="#" onclick="event.preventDefault(); document.getElementById('like_btn').click();"><img src="/likes_icon.png" style="height: 40px;width: 40px;" ></a><span id="like_num">{{\Illuminate\Support\Facades\DB::table("posts")->where("id",$post->id)->value("likes")}}</span>
                                 <input type="hidden" id="post_id"  value="{{$post->id}}">
                                <button style="display: none" id="like_btn"></button>

the route

Route::post('like', [App\Http\Controllers\ratesys::class, 'like'])->name('like');
May
26
2 weeks ago
Activity icon

Replied to How To Get The Comment On A Post To Load On Clicking The Comments Link

I didn't know a bout it, I am new to web development, this my first full stack project.

Activity icon

Started a new Conversation How To Get The Comment On A Post To Load On Clicking The Comments Link

I am coding a social network website, and I want to know how to get the comment on a post to load on clicking on comment link like in Facebook and the other websites.

May
19
3 weeks ago
Activity icon

Replied to Laravel Give Me GET Method Is Not Supported Despite Using Post In Bot The For And The Route

ok, I used wildcard {id} to get to user profile instead of post and now its working fine, thanks anyway.

Activity icon

Replied to Laravel Give Me GET Method Is Not Supported Despite Using Post In Bot The For And The Route

ok i edit it but the problem is still the same

document.getElementById('getuserid{{$user['id']}}')
Activity icon

Started a new Conversation Laravel Give Me GET Method Is Not Supported Despite Using Post In Bot The For And The Route

I am currently codeing a social network website, two of the functions of the website is doing follow and unfollow and the way do this is by searching for user name then chooseing user from the results

the user result code section

 @foreach($user as $user)

                    <div class="card">
                        @if($user['profile_img']!=null)
                        <div><img src="{{url('/images/users_profile_img/'.$user['profile_img'])}}" id="search-prof">

                            @else
                                <div><img src="images/user_default.png" id="search-prof">
                                    @endif
                                   <a style="text-decoration: none;color: black;" href="#"><span id="search-username" onclick="event.preventDefault(); document.getElementById('getuserid').submit();">{{$user['first_name']." ".$user['last_name']}}</span></a>
                                    <form action="{{ route('get-profile') }}" method="POST" id="getuserid" style="display: none;">
                                        @csrf
                                        <input type="hidden" name="user_id" value="{{ $user['id']}}">

                                    </form>
                                </div>

                    </div>
                        <br>
                @endforeach

as you can see above when the user click on on of the user results the app get its id in http request the send it to this controller to get this user profile

 public function get_all_data(Request $request)
    {
        $id=$request->input('user_id');

        $userdata=DB::table('users')->select('id','first_name','last_name','profile_img','cover_img')
            ->where('id',$id)->first();
        $is_exist=false;
        $user=DB::table('followers')->where('follower_id',$id)->where('id',auth()->id())->get();
        if(count($user)==1){$is_exist=true;}
        if($id!=auth()->id()) {
            return view('show-prof')->with(compact('userdata','is_exist'));
        }
        else

            return view('profile');

    }

then on the user have been directed to the profile page they have a button to follow or unfollow the user

 public function following(Request $request)
    {
        $follower=followers::create([
            'id'=>Auth::id(),
            'follower_id'=>$request->input('user_id'),
        ]);
        return back();
    }
    public function unfollowing(Request $request)
    {
        $u=DB::table('followers')->where('id',auth()->id())->where('follower_id',$request->input('user_id'),)->delete();
        return back();
    }

my routes

Route::get('search-results',  ['as' => 'search-results', 'uses' => 'App\Http\Controllers\[email protected]'])->middleware('auth');
Route::post('get-profile',  ['as' => 'get-profile', 'uses' => 'App\Http\Controllers\[email protected]_all_data'])->middleware('auth');
Route::post('follow', [App\Http\Controllers\follow::class, 'following'])->name('follow');
Route::post('unfollow', [App\Http\Controllers\follow::class, 'unfollowing'])->name('unfollow');

my problem is when i click in either follow or un follow the page redirect to this error page

The GET method is not supported for this route. Supported methods: POST. http://127.0.0.1:8000/get-profile

i want it to redirect to the previous profile page with the previous http request that contain the user id the reason i want to do this is to show that this user has been followed by changing the follow button i con like this

@if($is_exist==false)
            <button type="button" class="btn btn-light"><img src="/following_icon.png" id="home_icon" onclick="event.preventDefault(); document.getElementById('follow').submit();"><p>Follow</p></button>
                <form action="{{ route('follow') }}" method="POST" id="follow" style="display: none;">
                    @csrf
                    <input type="hidden" name="user_id" value="{{ $userdata->id }}">

                </form>
            @else
                <button type="button" class="btn btn-light active"><img src="/followed_icon.png" id="home_icon" onclick="event.preventDefault(); document.getElementById('unfollow').submit();"><p>Followed</p></button>
                <form action="{{ route('unfollow') }}" method="POST" id="unfollow" style="display: none;">
                    @csrf
                    <input type="hidden" name="user_id" value="{{ $userdata->id }}">
                </form>
            @endif

if any one have another way of doing this please comment it

May
18
3 weeks ago
Activity icon

Started a new Conversation How To Fix This 404 Not Found

I am trying to cod a follow function which will be called on click on button and the button will go to link"profile/{id} id is the id of the user you want to follow but when I click on the follow button it gave me 404 not found error

my blad file

<button type="button" class="btn btn-light"><img src="/following_icon.png" id="home_icon" onclick="event.preventDefault(); document.getElementById('follow').click();"><p>Follow</p></button>
            <a href="follow/{{$userdata->id}}" id="follow"></a>

my controller file

public function following()
    {
        $id=request()->segment(count(request()->segments()));
        $follower=followers::create([
            'id'=>Auth::id(),
            'follower_id'=>$id
        ]);
        return back();
    }

my route

Route::get('follow/{id}',  ['as' => 'follow/{id}', 'uses' => 'App\Http\Controllers\[email protected]'])->middleware('auth');
May
13
4 weeks ago
Activity icon

Replied to How To Excute This Query In Laravel?

thanks, it work, but the problem is that i want to replace mo with a variable name $key but when i tried to do that it didn't return any records

Activity icon

Started a new Conversation How To Excute This Query In Laravel?

the query I want to excute in laravel in pure sql

SELECT p.id,title,post_content,image_dir,video_dir,p.created_at,first_name,last_name,profile_img FROM users AS u,posts AS p WHERE title like '%mo%' OR post_content like '%mo%' AND user_id=u.id
May
12
1 month ago
Activity icon

Replied to How To Get The Foreign Key From Model Relationship And Use To Retrieve Database?

ok but I want to use it with $post query, I want to add (AND select profile image and username from table user where id is equal to the foreign key) so it all pass in one record

Activity icon

Started a new Conversation How To Get The Foreign Key From Model Relationship And Use To Retrieve Database?

I am coding a search function inside my social network website and I wanted to get the id of the user who posted a post with rest of the post data

my post query

$posts = posts::query()
        ->where('title', 'like', "%{$key}%")
        ->orWhere('post_content', 'like', "%{$key}%")
        ->orderBy('created_at', 'desc')
        ->get();

model relationship in post

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

model relationship in user

public function posts()
    {
        return $this->hasMany(posts::class);
    }
May
11
1 month ago
Activity icon

Replied to Laravel Keep Giving Me Undefined Variable Despite Returning The Variable In My Function

i tried this and now its working

 return view("$current")->with(compact( 'user', 'posts', 'post_num', 'user_num'))
        ->with($img_name);

thanks for your replays

Activity icon

Replied to Laravel Keep Giving Me Undefined Variable Despite Returning The Variable In My Function

the $vairables $prof_img and $username which are element of $img_name the error message is Undefined variable $prof_img (View: /home/mohamad/SocialNetwork/SocialNetwork/resources/views/search-results.blade.php)

no the function get_uer_name_and_img is in a different controller and the function call with working fine before i changed the code I tryed dd() and give me error that it can't work with an array

Activity icon

Replied to Laravel Keep Giving Me Undefined Variable Despite Returning The Variable In My Function

ok i tried your solution compact again and it worked with user, post, user_num and post num but it didn't work with img_name which hold the return value of function get_uer_name_and_img

get_uer_name_and_img function

public function get_uer_name_and_img()
    {
    $first = DB::table('users')->where('id', Auth::id())->value('first_name');
    $last= DB::table('users')->where('id', Auth::id())->value('last_name');
    $username=$first." ".$last;
    $prof_img=DB::table('users')->where('id', Auth::id())->value('profile_img');
    $cover_img=DB::table('users')->where('id', Auth::id())->value('cover_img');
     return (['username' => $username,'prof_img'=>$prof_img,'cover_img'=>$cover_img]);

    }

now it gives me undefined variable regarding the variable prof_img below

@if($prof_img!=null)
                    <img src="{{url('/images/users_profile_img/'.$prof_img)}}" id="userAvatar"><span class="ml-3">{{$username}}</span>
                @else
                    <img src="/images/user_default.png" id="userAvatar"><span class="ml-3">{{$username}}</span>
                @endif
Activity icon

Replied to Laravel Keep Giving Me Undefined Variable Despite Returning The Variable In My Function

it gave me this error compact(): Undefined variable $mohamad abedelhady and $current to get the whatever current route we are in

Activity icon

Replied to Laravel Keep Giving Me Undefined Variable Despite Returning The Variable In My Function

I changed it to user and still give the same error also the variable $user_num has no typo and it still give undefined variable error

Activity icon

Started a new Conversation Laravel Keep Giving Me Undefined Variable Despite Returning The Variable In My Function

laravel keep giving me undefined variable error when I try to use some variable from my function

my function

public function search(Request $request)
{
    $key = trim($request->input('q'));
    $posts = posts::query()
        ->where('title', 'like', "%{$key}%")
        ->orWhere('post_content', 'like', "%{$key}%")
        ->orderBy('created_at', 'desc')
        ->get();

    $user = User::query()
        ->where('first_name', 'like', "%{$key}%")
        ->orWhere('last_name', 'like', "%{$key}%")
        ->orderBy('created_at', 'desc')
        ->get();
    $user_num=$user->count();
    $post_num=$posts->count();
    $total=$user_num+$post_num;

    $img_name=app()->call('App\Http\Controllers\[email protected]_uer_name_and_img');
    $current=$request->path();
//  echo "$posts";
    return view("$current")->with($img_name,['users' => $user],['posts' => $posts],$post_num,$user_num);

as you can see in the code above I used echo to check if the database is returning results and it did , but when try to access the variables $user, $posts, $post_num or $user_num in blade page it give variable undefined error, but the variable $img_name which return two variable username and user profile img from the function get_uer_name_and_img is working fine

my blade view section where I call $user

 <div class="col-xl-7 col-lg-7 ">
    <div class="mr-5">
        <p class="h2 m-2">Search results</p>

        <div class="btn-group btn-group-lg m-2 " role="group" aria-label="Second group">
            <button type="button" class="btn btn-light"><span> All results</span></button>
            <button type="button" class="btn btn-light"><span>Users<span >{{" ".$user_num}}</span></span></button>
            <button type="button" class="btn btn-light"><span>Posts<span >{{" ".$post_num}}</span></span></button>
        </div>
            <p>{{$users}}</p>
    </div>

    </div>

my blade view section where i call $img_name

 @if($prof_img!=null)
                    <img src="{{url('/images/users_profile_img/'.$prof_img)}}" id="userAvatar"><span class="ml-3">{{$username}}</span>
                @else
                    <img src="/images/user_default.png" id="userAvatar"><span class="ml-3">{{$username}}</span>
                @endif

my route

Route::get('search-results',  ['as' => 'search-results', 'uses' => 'App\Http\Controllers\[email protected]'])->middleware('auth');
May
09
1 month ago
Activity icon

Replied to Image Upload Is Not Working

it gives the same errors with any image the input tag

<input type="file"  directory  accept="image/*" style="display: none;" id="upload-img" class="form-control" name="inputimg">

my form tag

 <form method="POST" action="{{route('crtpost')}}"
Activity icon

Started a new Conversation Image Upload Is Not Working

I am trying to upload an image but laravel keep sending me error and i dont know why

my function

 function store(Request $request)
   {
       $request->validate([
           'inputimg' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
       ]);

       $imageName = time().'.'.$request->image->extension();

       $request->image->move(public_path('images'), $imageName);

       

       return back()
           ->with('success','You have successfully upload image.')
           ->with('image',$imageName);
   }

my view

                    @csrf
                    <textarea class="form-control" id="textArea" rows="10" placeholder="text here" name="textinput"></textarea>
                    <p id="error-upload" style="display:none; color: red;"></p>
                    <div class="btn-group btn-group-sm m-2" role="group" aria-label="Second group" >
                        <button type="button" class="btn btn-light " onclick="event.preventDefault(); document.getElementById('upload-img').click();"><img src="/picture_icon.png" id="home_icon"><p>Picture</p></button>
                        <input type="file"  directory  accept="image/*" style="display: none;" id="upload-img" class="form-control" name="inputimg">
                        <button type="button" class="btn btn-light"onclick="event.preventDefault(); document.getElementById('upload-video').click();"><img src="/video_icon.png" id="home_icon"><p>Video</p></button>
                        <input type="file" accept="video/*" style="display: none;" id="upload-video" class="form-control" name="inputvid">


                    </div>
                    <input type="submit" class="btn btn-outline-info " style="width: 100%;" value="Post">
                </form>

my route

Route::post('crtpost',['as' => 'crtpost', 'uses' => 'App\Http\Controllers\[email protected]'])->middleware('auth');

the errors

The inputimg must be an image.

The inputimg must be a file of type: jpeg, png, jpg, gif, svg.

edit:

i commented this part

 $request->validate([
           'inputimg' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
       ]);

and this error comes out Call to a member function store() on null

Apr
11
2 months ago
Activity icon

Started a new Conversation How To Customize Laravel Fortify Validation Redirection Data?

I made a laravel app with one page for log in and registration forms, you can switch between them by clicking buttons that have java script that change their display attribute, I used laravel fortify for the authentication, and it works will the problem is when validation function find error in the registration form it redirect to the page but with the registration put on display:none, and you have to click on the signup button to make it appear, I asked in another form online and they suggested to us flash data or passing query string flag in the URL then make java script function to display the form, but now the problem is i don't know how to do that because I am using fortify for validation and it used the validate() method and it doesn't seem to allow for redirecting customization, does any one have a solution to this problem.

Apr
09
2 months ago
Activity icon

Started a new Conversation How To Use Laravel Fortify Without Making Separate Pages For Login/register

I made the home page in my website with two forms one For log in and another for sign up and I put a button with javascript code to switch between the two forms by hiding one of them with every click, now I want to attach those forms with laravel fortify but it the document says I have to make two pages for every forms and put their route in the boot function in fortify service provider, does any one know away to invoke fortify register functionality without making register. blade.