Jump to content

ali_254

Members
  • Posts

    97
  • Joined

  • Last visited

Posts posted by ali_254

  1. hi...

    i want create Validation form in laravel.... when run project , receive this error:

    The GET method is not supported for this route. Supported methods: POST.

     

    html form:

    <form action="/test2" method="post">
        {{csrf_field()}}
        <input type="text" name="title" id="title">
        <br>
        <input type="text" name="title2" id="title2">
        <br>
        <input type="text" name="title3" id="title3">
        <input type="submit" value="register">
    </form>
    

     

    route:

    Route::post('/test2', [Homecontroller::class, 'index3']);

     

    Homecontroller.php:

      public function index3(Request $request){
            $a=$request->post("title");
           echo $a . "</br>";
            $a2=$request->post("title2");
            echo $a2 . "</br>";
            $a3=$request->post("title3");
            echo $a3 . "</br>";
            $validated = $request->validate([
                'title' => 'required',
                'title2' => 'required',
            ]);
    
    
    
    
    
            return view('test2');
        }

     

     

    please guide me.thanks

  2. i also inter this code:

    composer create project laravel/laravel test 8.0

    but , result is:

      [InvalidArgumentException]
      Could not find package laravel/laravel with version 8.0 in a version installable using your PHP version, PHP extens
      ions and Composer version.

     

     PHP Version is 7.4.9

     

    whats problem? thanks

  3. hi...

    i install last version of composer and inter this code for install laravel:

    composer create-project --prefer-dist laravel/laravel blog

     

    Laravel is successfully installed but when inter code "php artsisan  --version" in terminal , result is version 5 !!!

    i  need to install laravel version 8 , whats problem? thanks

  4. 3 hours ago, requinix said:

    ok thanks , but i have a problem..

    i add this code in controller but variable $data1 in file blade.php Cannot be identified

    class FlightController extends Controller
    {
    
    
    public function function1(Request $request,$id ){
    
        $data1=Flight::find($id);
    
    
        return view('audi')->with('id',$id)->with('a',$data1);
    }
    
    
    }

     

    error:

    (2/2) ErrorException

    Undefined variable: data1 (View: C:\wamp64\www\Amozesh_php\shoplaravel\resources\views\audi.blade.php)

     

    file blade.php:

    
    
    @extends('layout.master')
    
    @section('content')
        <h2>ali niknami</h2>
    @endsection
    
    
    {{ $data1 }}
    
    
    
    
    
    <form action="/users/insert" method="post">
        {{csrf_field()}}
    
    
        <input type="text" name="title" id="title">
        <br>
        <input type="text" name="title2" id="title2">
        <br>
        <input type="text" name="title3" id="title3">
        <input type="submit" value="register">
    </form>
    
    
    
    

     

  5. hi...

    i create two table in laravel and I created a "join" operation between them.

     

    controller file:

    class FlightController extends Controller
    {
    
    
    public function function1(Request $request,$id ){
    
        $data1=Flight::find($id);
        $a=$data1->FlightComment();
    
        dd($a);
    
    
    
        return view('audi')->with('id',$id)->with('a',$a);
    }
    
    
    }

     

    Variable "A" is an array, how can I display it in file "blade.php"? thanks

     

    Flight table:

    flights.thumb.jpg.936d345fe0227a02ebd6da7da06ef501.jpg

     

     

    FlightComment:

    flight_comments.thumb.jpg.d6c0e798fa4938e2c77d1746996b7028.jpg

  6. hi ...

    I made a table called: flights , Also, I want to create another table and run the "join" operation between them. this table called: flight_comments

     

    table flights:

     public function up()
        {
            Schema::create('flights', function (Blueprint $table) {
                $table->bigIncrements('id');
                $table->string('name');
                $table->string('email')->unique();
                $table->timestamp('email_verified_at')->nullable();
                $table->string('password');
                $table->rememberToken();
                $table->timestamps();
    
    
            });

     

    table flight_comments:

      public function up()
        {
            Schema::create('flight_comments', function (Blueprint $table) {
                $table->bigIncrements('id');
                $table->bigInteger('flight_id')->unsigned();
                $table->string('body','140');
                $table->nullabletimestamps();
                $table->foreign('flight_id')->references('id')->on('flights')->onDelete('cascade');
            });
        }

     

    When I run the "migration" command, I get the following error:

     

    In Connection.php line 647:

      SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint (SQL: alter table `flight_comments` add constraint `flight_
      comments_flight_id_foreign` foreign key (`flight_id`) references `flights` (`id`) on delete cascade)


    In Connection.php line 449:

      SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint

     

     

    please guide me

  7. hi...

     

    i create model of eloquent end create table....

    in file controller , i add this code but return null😪

        public function index2(Request $request,$id){
    
    
    $data1=Motorolla::find($request['1']);
    
    dd($data1);
    
    
           return view('audi')->with('id',$id)->with('data1',$data1);
        }

     

     

    file web.php:

    Route::get('/audi/{id}','HomeController@index2' );

     

    table motorolla:

      public function up()
        {
            Schema::create('motorollas', function (Blueprint $table) {
                $table->bigIncrements('id');
                $table->string('name');
                $table->string('address');
    
                $table->string('password');
    
                $table->timestamps();
            });

     

  8. 1 hour ago, requinix said:

    Are you sure you put Ultimate.php in the right place? What's the code in that file?

    thanks , yes!

     

    file Ultimate.php:

    <?php
    
    namespace App;
    
    use Illuminate\Database\Eloquent\Model;
    
    class Ultimate extends Model
    {
        //
    }

     

    error2.thumb.jpg.5f4f4968e7e34ab3bc410fb717676156.jpg

  9. hi...

     

    I want to show the tables with Eloquent.

    i create one model in folder "app" and create migratione .

    in file controller add this codes :

     

    <?php
    
    namespace App\Http\Controllers;
    
    use Illuminate\Http\Request;
    use app\Ultimate;
    
    class HomeController extends Controller
    {
    
    
        //
    
    
    
        public function index2(Request $request,$id){
    
    
    $data1=Ultimate::all();
    dd($data1);
    
           return view('users')->with('id',$id);
        }
    }

     

    But at runtime, an error occurs.

    error :

    (1/1) FatalErrorException

    Class 'app\Ultimate' not found

    in HomeController.php line 19

     

     

    whats problem? thanks

  10. 43 minutes ago, kicken said:

    Databases don't have a concept of order when inserting data.  The data is stored in whatever location it will fit.

    You can only define an order when you're reading data back out of the database using a SELECT query and you do that by using an ORDER BY clause in your query. 

    So if you want your data to display in a specific order, you MUST change your query to include an ORDER BY clause that specifies the ordering you want.

    thank you

  11. 2 hours ago, kicken said:

    It doesn't matter where in the table the data is stored.  When you query your data you want to specify an ORDER BY clause to define what order it will be returned in.

    If you want the records to display in the order the were added, make sure you have a field that records what date and time the record was added and sort by that field.

     

     

    thank you.

    When I add a query And display it in a grid , Unfortunately The information is not displayed correctly again...

    Actually , Information when added not stored properly...Is there a solution to this problem? Or should the "query" solve the problem?

     

    Quote

    make sure you have a field that records what date and time the record was added and sort by that field.

    Do you have an example and source code for this?

    grid.jpg

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.