marioeid

marioeid

Member Since 8 Months Ago

cairo

Experience Points 4,110
Experience Level 1

890 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 32
Lessons
Completed
Best Reply Awards 0
Best Reply
Awards
  • start-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-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-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist 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.

05 Feb
6 months ago

marioeid started a new conversation I Did The Tags To Posts Many To Many Relationship How To Input The Tags In A Form Like Laracast When You Are Posting

what i want to do is to have a drop down list with some static options in it like the one in laracast when i am posting i have to select a channel how to do it inside my form that when he chooses this list element it will set the id equal to the static id of the list element and the name equal to the static name of the list element

17 Jan
7 months ago

marioeid left a reply on Laravel Syntax In Vs Code

@NEOIGHODARO - it worked thanks

marioeid left a reply on Laravel Syntax In Vs Code

<div class="row">
                        <span class="circle">what's C++?<br></span>
                        <p>
                            c++ is an intermediate-level programming language which is known by it's fast performance and
                            it is also extension of the C language (another programming language) it can be written in two
                            ways "C style" or "object-oriented style." we will discus the oop style in detail
                        </p>
                        <span class="circle">what we need to start?<br></span>
                        <p>
                            before you start writting your code you need to use IDE stands for (Integrated development environment)
                            so watch this video
                            <a href="https://www.youtube.com/watch?v=3B4hPHZNtNw" target="_blank">install code blocks</a> it will show you how to download and install codeblocks and which compiler to be used
                        </p>
                        <span class="circle">Compiler <br></span>
                        A compiler is a special program that processes statements written in a particular programming language and turns them into machine language or "code" that a computer's processor uses
                    </div>

this the code in vs it makes the color after it's or any single quote change till it meets another one

marioeid left a reply on Laravel Syntax In Vs Code

@JLRDW - i want to share a photo cause the code won't show the color change and i don't know how to share it

marioeid started a new conversation Laravel Syntax In Vs Code

i have a problem in vs code in paragraph tag any single quote misses the color of the entire code and i don't know how to fix it and it also makes the code very hard to keep track off when i write words like it's or don't etc... it changes the color after the single quote till it finds another single quote it's like opening and closing for something

01 Jan
7 months ago

marioeid started a new conversation How To Tell The Database That This Comment Belongs To This Post In Storemethod (saving Stage)?

if i have a post and comments belong to that post and i am receiving the post id in store method in commentscontroller after associating the body and the title how to save the comment telling the database that this comment belongs to this post my store method

    public function store(Request $post)
      {
            $this->validate($post,['body'=>'required','title'=>'required']);
            $comment=new comments;
            $comment->body=request('body');
            $comment->title=request('title');
            $post->comments()->save($comment);
          // $post->id = $id;
            $response = array(
            'status' => 'success',
            'data' => $comment,
        );
            return response()->json($response); 
      }

comments.php

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class comments extends Model
{
    //
    public function post()
    {
    return $this->belongsTo('App\Post');
    }
    
}

post.php

<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Post extends Model
{
    //
    public function user()
    {
    return $this->belongsTo(User::class);
    }
    public function comments()
    {
      return $this->hasMany(comments::class);
    }
}

marioeid left a reply on How To Pass The Csrf_token To My View Using Ajax Jquery

@MCSTEPP - yes it wasn't but i solved the issue i don't even need to use form if am using ajax to create or delete

18 Dec
8 months ago

marioeid left a reply on How To Use Append In Ajax Success Function To Add {{csrf_token()}}

@D9705996 - the data is right in inspect in chrome every data is right expect the token the token is undefined and i don't know why

marioeid started a new conversation How To Use Append In Ajax Success Function To Add {{csrf_token()}}

when i click post i append list inside it there's alink with data-token i want to set that data-token value to {{csrf_token()}} but it doesn't work when i use data.data.token it appears in the view as data-token= undefined my success ajax call

$.ajax({
        // headers: {
        //     'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        //   }
        //   ,        
    url:'/createpost',
    type:'POST',
    data:$(".postform").serialize(),
    dataType: 'JSON',
   success:function(data)
   {
     
      if(data.status == "success"){


      $('#posts').append('<li class="arrow_box col-md-10 col-lg-10 offset-lg-1"><p><span id="title">'+data.data.title+'</span><br/><span id="body">'+data.data.body+'</span>               <br/><div class="info"><p> <div id="funform"> <div>'+data.data.created_at+'</div><a  class="fa fa-trash post_delete" data-token='+data.data.token+' data-id="'+data.data.id+'" data-url="/deletepost/'+data.data.id+'"></a><a class="fa fa-thumbs-up post_like"></a>   <a class="fa fa-comment post_comment"></a> <a class="fa fa-edit post_edit" </a></a>  </div> </p>  </div></p></li>');
      
      $('.close').click();
      $( '.postform' ).each(function(){
        this.reset();
    });
    
    }
     }
   ,error:function(data)
   {
     $('#errors').show();
     $('#errors').html('');
       var errors=data.responseJSON;
       $.each(errors,function(v,k)
       
       {
        $('#errors').append(v+"<br/>");

       }
       );
   }
   
    })



    });
    ```

marioeid left a reply on How To Pass The Csrf_token To My View Using Ajax Jquery

csrf_field isn't working in jquery i tried that before

marioeid left a reply on How To Pass The Csrf_token To My View Using Ajax Jquery

@PALAK27 - i am not asking how to pass to the data i am asking in the post function i am showing a new post how to put it in the view like

$('#posts').append('<a data-token="{{csrf_token()}}"></a>');
17 Dec
8 months ago

marioeid started a new conversation How To Pass The Csrf_token To My View Using Ajax Jquery

the ajax function works but when i append i don't know how to pass the csrf_token to the jquery append function

 $('#post_create').on('click', function(e){
    
    //  var url=$(this).attr('action');
    //  var post=$(this).attr('method');
    e.preventDefault();
    //  var body=$('#body').val();
    //  var tilte=$('#title').val();
    $.ajax({
        // headers: {
        //     'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        //   }
        //   ,        
    url:'/createpost',
    type:'POST',
    data:$(".postform").serialize(),
    dataType: 'JSON',
   success:function(data)
   {
     
      if(data.status == "success"){


      $('#posts').append('<li class="arrow_box col-md-10 col-lg-10 offset-lg-1"><p><span id="title">'+data.data.title+'</span><br/><span id="body">'+data.data.body+'</span>               <br/><div class="info"><p> <div id="funform"> <div>'+data.data.created_at+'</div><a  class="fa fa-trash post_delete" data-id="'+data.data.id+'" data-url="/deletepost/'+data.data.id+'"></a><a class="fa fa-thumbs-up post_like"></a>   <a class="fa fa-comment post_comment"></a> <a class="fa fa-edit post_edit" </a></a>  </div> </p>  </div></p></li>');
      
      $('.close').click();
      $( '.postform' ).each(function(){
        this.reset();
    });
    
    }
     }
   ,error:function(data)
   {
     $('#errors').show();
     $('#errors').html('');
       var errors=data.responseJSON;
       $.each(errors,function(v,k)
       
       {
        $('#errors').append(v+"<br/>");

       }
       );
   }
   
    })



    });

my view

<div class="container-fluid">
        <div class="page col-lg-12">
          
            <ul id="posts" class="row">
                 @foreach($posts as $post)
                    <li class="arrow_box col-md-10 col-lg-10 offset-lg-1">
                    <p><span class="username">{{$post->user->name}} </span> &nbsp<span id="title">{{$post->title}}</span>
                    
                    <br/>
               <span id="body">{{$post->body}}</span>
                                   <br/>
                    <div class="info">
                    <p> 
                   <div id="funform">
                    <div>{{$post->updated_at->format('d M Y - H:i:s')}}</div>
                  <a  class="fa fa-trash post_delete" data-token="{{ csrf_token() }}" data-id="{{$post->id}}" data-url="/deletepost/{{$post->id}}"></a>
                   <a class="fa fa-thumbs-up post_like"></a>
                   <a class="fa fa-comment post_comment"></a>
                   <a class="fa fa-edit post_edit" </a></a>
                   </div> 
                   </p>
                   </div>
                    
                    </p>
                    
                    </li>
                @endforeach
                
            </ul>
             <button class="btn mybtn right" data-toggle="modal" data-target="#exampleModalCenter">post</button>
 
            <!-- Button trigger modal -->

marioeid left a reply on How To Access The Username If I Have The Post Using Eloquent

thanks i am just looking stupid right now it worked :) thanks

marioeid started a new conversation How To Access The Username If I Have The Post Using Eloquent

i am using post->user->name but it throws this error and the post contains the user id

Trying to get property 'name' of non-object (View: D:\courses\web\web_projects\nuts_of_C++\resources\views\blog.blade.php)

my view

@foreach($posts as $post)
                    <li class="arrow_box col-md-10 col-lg-10 offset-lg-1">
                    <p><span class="sl">{{$post->user->name}}</span><span id="title">{{$post->title}}</span>
                    
                    <br/>
               <span id="body">{{$post->body}}</span>
                                   <br/>
                    <div class="info">
                    <p> 
                   <div id="funform">
                    <div>{{$post->updated_at->format('d M Y - H:i:s')}}</div>
                  <a  class="fa fa-trash post_delete" data-token="{{ csrf_token() }}" data-id="{{$post->id}}" data-url="/deletepost/{{$post->id}}"></a>
                   <a class="fa fa-thumbs-up post_like"></a>
                   <a class="fa fa-comment post_comment"></a>
                   <a class="fa fa-edit post_edit" </a></a>
                   </div> 
                   </p>
                   </div>
                    
                    </p>
                    
                    </li>
                @endforeach
          

my user table

<?php

namespace App;

use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use Notifiable;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name', 'email', 'password',
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];
    public function posts()
    {
      return $this->hasMany('App\Post');
    }
}

my post table

<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Post extends Model
{
    //
    public function user()
    {
     $this->belongsTo('App\User');
    }
}

marioeid left a reply on I Get Error 500 When Trying To Post A Long Post

the migration

<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreatePostsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('posts', function (Blueprint $table) {
           $table->increments('id');
           $table->string('body');
           $table->string('title');
           $table->integer('user_id');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('posts');
    }
}

marioeid started a new conversation I Get Error 500 When Trying To Post A Long Post

it posts normally when the body is short and i don't know if there's a limit to how many (char) i could use or string size the route

<?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/', '[email protected]');
Route::get('/blog', '[email protected]');
Auth::routes();
Route::get('/home', '[email protected]')->name('home');
Route::get('ajax', function(){ return view('ajax'); });
Route::post('/postajax','[email protected]');
Route::post('/createpost','[email protected]');
Route::delete('/deletepost/{id}',['uses'=>'[email protected]','as'=>'post.delete','middleware'=>'auth']);

the ajax

 $('#post_create').on('click', function(e){
    
    //  var url=$(this).attr('action');
    //  var post=$(this).attr('method');
    e.preventDefault();
    //  var body=$('#body').val();
    //  var tilte=$('#title').val();
    $.ajax({
        // headers: {
        //     'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        //   }
        //   ,        
    url:'/createpost',
    type:'POST',
    data:$(".postform").serialize(),
    dataType: 'JSON',
   success:function(data)
   {
     
      if(data.status == "success"){


      $('#posts').append('<li class="arrow_box col-md-10 col-lg-10 offset-lg-2"><p><span id="title">'+data.data.title+'</span><br/><span id="body">'+data.data.body+'</span>               <br/><div class="info"><p> <div id="funform"><a   <a  class="fa fa-trash post_delete" data-id="'+data.data.id+'" data-url="/deletepost/'+data.data.id+'"></a><a class="fa fa-thumbs-up post_like"></a>   <a class="fa fa-comment post_comment"></a> <a class="fa fa-edit post_edit" </a></a>  </div> </p>  </div></p></li>');
      
      $('.close').click();
      $( '.postform' ).each(function(){
        this.reset();
    });
    
    }
     }
   

the view the modal contain the form

<!doctype html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
    <link rel="stylesheet" href="css/blog.css">
    <link rel="stylesheet" href="http://fonts.googleapis.com/css?family=UnifrakturMaguntia">
    <link rel="stylesheet" href="/mathscribe/jqmath-0.4.3.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
    <link href="https://fonts.googleapis.com/css?family=Prociono" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css?family=Playfair+Display" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css?family=Dancing+Script" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css?family=Anton|Bitter|Noto+Serif|Roboto+Slab" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css?family=Abril+Fatface|Courgette|Crimson+Text|Great+Vibes|Kaushan+Script|Merienda|Old+Standard+TT|Pacifico|Satisfy" rel="stylesheet">
  

    <title>BLOG</title>
</head>

<body>
    <div class="interface">
        <img class="sz" src="img/iphone_ipad_apple_watches_stylus_pen_style_99204_2560x1080.jpg">
        <div class="centered">C++ Blog</div>
        <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 col-12 text-center centered2">
            <i class="fa fa-google-plus cir"></i>
            <i class="fa fa-facebook cir"></i>
            <i class="fa fa-twitter cir"></i>
           
        </div>
    </div>
    
    <div class="container-fluid">
        <div class="page col-lg-12">
          
            <ul id="posts" class="row">
                 @foreach($posts as $post)
                
                    <li class="arrow_box col-md-10 col-lg-10 offset-lg-2">
                    <p><span id="title">{{$post->title}}</span>
                    
                    <br/>
               <span id="body">{{$post->body}}</span>
                                   <br/>
                    <div class="info">
                    <p> 
                   <div id="funform">
                    
                  <a  class="fa fa-trash post_delete" data-token="{{ csrf_token() }}" data-id="{{$post->id}}" data-url="/deletepost/{{$post->id}}"></a>
                   <a class="fa fa-thumbs-up post_like"></a>
                   <a class="fa fa-comment post_comment"></a>
                   <a class="fa fa-edit post_edit" </a></a>
                   </div> 
                   </p>
                   </div>
                    
                    </p>
                    
                    </li>
                @endforeach
                
            </ul>
             <button class="btn mybtn right" data-toggle="modal" data-target="#exampleModalCenter">post</button>
 
            <!-- Button trigger modal -->

<!-- Modal -->
      <form class="postform">
        {{ csrf_field() }}
        <div class="modal fade" id="exampleModalCenter" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
  <div class="modal-dialog modal-dialog-centered modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header">
          <textarea id="formtitle" class="title" placeholder="Add your title" name="title"></textarea>
           
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
              
            <div class="form-group">           
             <textarea  id="formbody" name="body"  class="bl" placeholder="Add your body"></textarea>
            </t>
            </div>
            <button   id="post_create" class="btn mybtn right">post</button>
 
      </div>
    </div>
  </div>





  </form>
  </div>

        </div>
      <div id="errors"></div>
      

    </div>




    <script src="/mathscribe/jquery-1.4.3.min.js"></script>
    <script src="/mathscribe/jqmath-etc-0.4.6.min.js" charset="utf-8"></script>


    <script src="https://code.jquery.com/jquery-3.3.1.js" integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60=" crossorigin="anonymous"></script>
    <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
    <script src="https://code.jquery.com/jquery-1.11.1.js" integrity="sha256-MCmDSoIMecFUw3f1LicZ/D/yonYAoHrgiep/3pCH9rw=" crossorigin="anonymous">
    </script>
    <script src="https://code.jquery.com/ui/1.12.0/jquery-ui.js" integrity="sha256-0YPKAwZP7Mp3ALMRVB2i8GXeEndvCq3eSl/WsAl1Ryk=" crossorigin="anonymous"></script>

      <script src="https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js"></script>

       <script src="js/BLOG.js">


    </script>




</body>



</html>
13 Dec
8 months ago

marioeid left a reply on Error 419 But I Am Passing The Token

still the same error

marioeid started a new conversation Error 419 But I Am Passing The Token

when i click delete it gives me error 419 still don't know why but it doesn't work my routes


Route::get('/', '[email protected]');
Route::get('/blog', '[email protected]');
Auth::routes();
Route::get('/home', '[email protected]')->name('home');
Route::get('ajax', function(){ return view('ajax'); });
Route::post('/postajax','[email protected]');
Route::post('/createpost','[email protected]');
Route::delete('/deletepost/{id}',['uses'=>'[email protected]','as'=>'post.delete','middleware'=>'auth']);

my view

  <ul id="posts" class="row">
                 @foreach($posts as $post)
                
                    <li class="arrow_box col-md-10 col-lg-10 offset-lg-2">
                    <p><span id="title">{{$post->title}}</span>
                    
                    <br/>
               <span id="body">{{$post->body}}</span>
                                   <br/>
                    <div class="info">
                    <p> 
                   <div id="funform">
                   <meta name="csrf-token" content="{{ csrf_token() }}">

                  <a  class="fa fa-trash post_delete" data-id="{{$post->id}}" data-url="/deletepost/{{$post->id}}"></a>
                   <a class="fa fa-thumbs-up post_like"></a>
                   <a class="fa fa-comment post_comment"></a>
                   <a class="fa fa-edit post_edit" </a></a>
                   </div> 
                   </p>
                   </div>
                    
                    </p>
                    
                    </li>
                @endforeach
                
            </ul>

my ajax note: there's only one class called post_delete in my view

 $('.post_delete').on('click',function(e)
    {
        e.preventDefault();
         var id = $(this).data("id");
         var url=$(this).data("url");
         var th=$(this).parent().parent().parent();    
        $.ajax({
            url:url,
            type: 'DELETE',
            data: {  "_token": "{{ csrf_token() }}"},
            dataType: 'JSON',
            success:function(data)
            {
               th.remove();
            },
        });
    }
08 Dec
8 months ago

marioeid started a new conversation Ajax Laravel

i did this but now after i retraive data i want to send it to the data base and show it in the same page witout reloading the page the success function is working after i retraive data now i don't save it in the database i just get it and if i show the data in the view using jquery what if i posted two times( click post) will it work and is this the right way to show data on my view my js

$(document).on("ready", function () {
    // start up hidden
    $('#errors').hide();
    $('.interface').hide();
    $('.centered').hide();
    $('.centered2').hide();
    $('.page').hide();
    // show the page
    $('.interface').slideDown(2000);
    $('.centered').slideDown(3000);
    $('.centered2').slideDown(3000);
    $('.page').slideDown(3000);
    $('#post_create').on('click', function(e){
     e.preventDefault();
     var url=$(this).attr('action');
     var post=$(this).attr('method');
     var data=$(this).serialize();
    $.ajax({
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
          }
          ,        
    type:post,
    url:url,
    data:data,
    contenttyp:"form/data",
    processData:false,
   success:function(data)
     {
      alert('hello');
     }
   ,error:function(data)
   {
     $('#errors').show();
     $('#errors').html('');
       var errors=data.responseJSON;
       $.each(errors,function(v,k)
       
       {
        $('#errors').append(v+"<br/>");

       }
       );
   }
   
    })



    });
});

my controller

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\post;
class Postcontroller extends Controller
{
    //
    public function store(Request $request)
    {
      $this->validate($request,['body'=>'required|max:1000','title'=>'required|max:1000']);
        $post=new Post;
        $post->body=request('body');
        $post->title=request('title');
        $request->user()->posts()->save($post);
       return $post;
    }
    public function destroy($id)
    {
      $post=Post::find($id)->first();
      $post->delete();
      return redirect('/blog');
    }
}

07 Dec
8 months ago

marioeid left a reply on How To Use Ajax In Laravel ?

@cronix i did this but now how after i retraive data i send it to the data base and show it in the same page witout updating success is working after i retraive data now i don't save it and if i show the data using jquery what if i posted two times will it work and is this the right way to show data on my view my js

$(document).on("ready", function () {
    // start up hidden
    $('#errors').hide();
    $('.interface').hide();
    $('.centered').hide();
    $('.centered2').hide();
    $('.page').hide();
    // show the page
    $('.interface').slideDown(2000);
    $('.centered').slideDown(3000);
    $('.centered2').slideDown(3000);
    $('.page').slideDown(3000);
    $('#post_create').on('click', function(e){
     e.preventDefault();
     var url=$(this).attr('action');
     var post=$(this).attr('method');
     var data=$(this).serialize();
    $.ajax({
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
          }
          ,        
    type:post,
    url:url,
    data:data,
    contenttyp:"form/data",
    processData:false,
   success:function(data)
     {
      alert('hello');
     }
   ,error:function(data)
   {
     $('#errors').show();
     $('#errors').html('');
       var errors=data.responseJSON;
       $.each(errors,function(v,k)
       
       {
        $('#errors').append(v+"<br/>");

       }
       );
   }
   
    })



    });
});

my controller

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\post;
class Postcontroller extends Controller
{
    //
    public function store(Request $request)
    {
      $this->validate($request,['body'=>'required|max:1000','title'=>'required|max:1000']);
        $post=new Post;
        $post->body=request('body');
        $post->title=request('title');
        $request->user()->posts()->save($post);
       return $post;
    }
    public function destroy($id)
    {
      $post=Post::find($id)->first();
      $post->delete();
      return redirect('/blog');
    }
}

marioeid left a reply on How To Use Ajax In Laravel ?

@CRONIX - thanks alot when i return $post are the success:function(data) the data will be every thing returned in the conroller?

marioeid started a new conversation How To Use Ajax In Laravel ?

i am new to laravel i have kind of small blog post project i want to show the posts witout reloading i tried a simple method but still don't know how to do it and show the posts witout reloading the page i am using jquery routes

<?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/', '[email protected]');
Route::get('/blog', '[email protected]');
Auth::routes();
Route::get('/home', '[email protected]')->name('home');
Route::post('/createpost','[email protected]');
Route::get('/deletepost/{id}',['uses'=>'[email protected]','as'=>'post.delete','middleware'=>'auth']);

post controller

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\post;
class Postcontroller extends Controller
{
    //
    public function store(Request $request)
    {
      $this->validate($request,['body'=>'required|max:1000','title'=>'required|max:1000']);
        $post=new Post;
        $post->body=request('body');
        $post->title=request('title');
        $request->user()->posts()->save($post);
       return redirect('/blog');
    }
    public function destroy($id)
    {
      $post=Post::find($id)->first();
      $post->delete();
      return redirect('/blog');
    }
}

my blog view

<!doctype html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
    <link rel="stylesheet" href="css/blog.css">
    <link rel="stylesheet" href="http://fonts.googleapis.com/css?family=UnifrakturMaguntia">
    <link rel="stylesheet" href="/mathscribe/jqmath-0.4.3.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
    <link href="https://fonts.googleapis.com/css?family=Prociono" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css?family=Playfair+Display" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css?family=Dancing+Script" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css?family=Anton|Bitter|Noto+Serif|Roboto+Slab" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css?family=Abril+Fatface|Courgette|Crimson+Text|Great+Vibes|Kaushan+Script|Merienda|Old+Standard+TT|Pacifico|Satisfy" rel="stylesheet">


    <title>BLOG</title>
</head>

<body>
    <div class="interface">
        <img class="sz" src="img/iphone_ipad_apple_watches_stylus_pen_style_99204_2560x1080.jpg">
        <div class="centered">C++ Blog</div>
        <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 col-12 text-center centered2">
            <i class="fa fa-google-plus cir"></i>
            <i class="fa fa-facebook cir"></i>
            <i class="fa fa-twitter cir"></i>
           
        </div>
    </div>

    <div class="container-fluid">
        <div class="page col-lg-10 offset-lg-1">
          
            <ul>
                 @foreach($posts as $post)
                
                    <li>
                    <p><span id="title">{{$post->title}}</span>
                    
                    <br/>
               <span id="body">{{$post->body}}</span>
                                   <br/>
                    <div class="row info">
                    <p> <a href="#">like</a> 
                     <a href="#">comment</a>
                     <a href={{route('post.delete',['id'=>$post->id])}}>delete</a>
                    </p></div>
                    <hr>
                 
                    </p>
                    
                    </li>
                
                @endforeach
                
            </ul>
             <button class="btn mybtn right" data-toggle="modal" data-target="#exampleModalCenter">post</button>
 
            <!-- Button trigger modal -->

<!-- Modal -->
      <form class="postform" method="POST" action="/createpost" >
      {{csrf_field()}}
<div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
  <div class="modal-dialog modal-dialog-centered" role="document">
    <div class="modal-content">
      <div class="modal-header">
          <textarea class="title" placeholder="Add your title" name="title"></textarea>
           
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
              
            <div class="form-group">           
             <textarea  name="body"  class="bl" placeholder="Add your body"></textarea>
            </t>
            </div>
            <button   id="post_create" type="submit" class="btn mybtn right">post</button>
 
          
            <hr>

      </div>
    </div>
  </div>





  </form>
  </div>

        </div>

    </div>




    <script src="/mathscribe/jquery-1.4.3.min.js"></script>
    <script src="/mathscribe/jqmath-etc-0.4.6.min.js" charset="utf-8"></script>


    <script src="https://code.jquery.com/jquery-3.3.1.js" integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60=" crossorigin="anonymous"></script>
    <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
    <script src="https://code.jquery.com/jquery-1.11.1.js" integrity="sha256-MCmDSoIMecFUw3f1LicZ/D/yonYAoHrgiep/3pCH9rw=" crossorigin="anonymous">
    </script>
    <script src="https://code.jquery.com/ui/1.12.0/jquery-ui.js" integrity="sha256-0YPKAwZP7Mp3ALMRVB2i8GXeEndvCq3eSl/WsAl1Ryk=" crossorigin="anonymous"></script>
       <script src="js/BLOG.js">


    </script>




</body>



</html>

what i am trying to achieve in ajax but i don't think that's the right way and still don't know how to do it

$(document).on("ready", function () {
    // start up hidden
    $('.interface').hide();
    $('.centered').hide();
    $('.centered2').hide();
    $('.page').hide();
    // show the page
    $('.interface').slideDown(2000);
    $('.centered').slideDown(3000);
    $('.centered2').slideDown(3000);
    $('.page').slideDown(3000);
    $('#post_create').on('click', function(e){
     e.preventDefault();
    $.ajax({
    method:'POST',
    url:'/createpost',
    data:{body:$('#body').val(),title:$('#tilte').val(),_token: CSRF_TOKEN},
   succsess:function(data)
   {
      alert('hello');
   }
   
    })



    });
});
30 Nov
8 months ago

marioeid started a new conversation SQLSTATE[HY000] [1045] Access Denied For User 'homestead'@'localhost' (using Password: YES) (SQL: Insert Into `users` (`email`, `password`, `user_name`, `updated_at`, `created_at`) Values (a, A, A, 2018-12-01 00:04:08, 2018-12-01 00:04:08))

i read about the error in stack over flow and in laravel discussions but still that didn't fix it my user table

<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateUsersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->increments('id');
            $table->timestamps();
            $table->string('user_name');
            $table->string('email');
            $table->string('password');
            
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('users');
    }
}

my view


      <form method="POST" action="/signup">
                 {{ csrf_field() }}
        <div class="form-group">
            <label>user name</label>
            <input type="text" class="form-control" name="user_name" placeholder="username">
        </div>
       
        <div class="form-group">
            <label class="me">Email address</label>
            <input type="text" class="form-control" aria-describedby="emailHelp" placeholder="Enter email" name="email">
            <small id="emailHelp" class="form-text text-muted">We'll never share your email with anyone else.</small>
        </div>
        <div class="form-group">
            <label>Password</label>
            <input type="text" name="password" class="form-control" placeholder="Password">
        </div>
        <div class="form-check">
            <input type="checkbox" class="form-check-input" id="exampleCheck1">
            <label class="form-check-label">Check me out</label>
        </div>
        
        <button type="submit" class="btn btn-primary">Submit</button>
    </form>

my user controller


<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\user;
class usercontroller extends Controller
{
    //
    public function signup(Request $request)
    {
        $user=new user;
      $user->email=request('email');
      $user->password=request('password');
      $user->user_name=request('user_name');
      $user->save();
      return redirect('/');
    }
    public function singin(Request $request)
    {

    }
}

my routes

<?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/', '[email protected]');
Route::get('/blog', '[email protected]');
Route::post('/signup','[email protected]');
21 Nov
8 months ago

marioeid started a new conversation Can I Use Algorithms In Laravel Or In Database Or In Web Development In General

i learned laravel basics and i love it it's simple and amazing but still very beginner in web development in general so i want to know that what if i want apply algorithms in backend for specific task laravel or database or using elquonet example (using binary search on sorted data for example how can i do it and can i do it in the database or does the database already uses binary search and that kind if algorithms ) my question in general if i could use the algorithms in backend and in web in general