jeudi 6 janvier 2022

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'mkstudent.classes_student' doesn't exist (SQL: insert into `classes_student` (`classes_id`,

i dont know why it is going to store in mkstudent.classes_student table , i mean i created many to many table class_student and when i tray to store a a student that have a class this error is happening any one who can help me please? the code is here student controller

public function store(createstudentrequest $request)
    {

       $student= Student::create([
            'first_name'=>$request->first_name,
            'last_name'=>$request->last_name,
            'phone_number'=>$request->phone_number
        ]);

        if($request->class){
            $student->classe()->attach($request->class);
        }

        session()->flash('success','student added successfully');
        return redirect(route('students.index'));
    }

student.create

<form action="" method="POST" enctype="multipart/form-data" >
            @csrf
            <div class="form-group">
                <label for="title">First Name</label>
                <input type="text" name="first_name" class="form-control" value="">
            </div>
            <div class="form-group">
                <label for="title">Last Name</label>
                <input type="text" name="last_name" class="form-control" value="">
            </div>
            <div class="form-group">
                <label for="title">Phone Number</label>
                <input type="text" name="phone_number" class="form-control" value="">
            </div>
            <div class="form-group">
                <label for="Class">Class</label>
                @if($classes->count() > 0)
                <select name="class[]" id="class" multiple="true" class="form-control">
                    @foreach($classes as $class)
                    <option value="">
                        
                    </option>
                    @endforeach
                </select>
                @endif
            </div>

and the migration for class_student is

 public function up()
    {
        Schema::create('class_student', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->integer('classes_id');
            $table->integer('student_id');
            $table->timestamps();
        });
    }

and in the student model


class Student extends Model
{
     protected $fillable = [
        'first_name','last_name','phone_number'
    ];

    public function classe()
    {
      return $this->belongsToMany(Classes::class);
    }
}

in the classes model

 public function students()
    {
        return $this->belongsToMany(Student::class);
    }


via Chebli Mohamed

mercredi 5 janvier 2022

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'mkstudent.classes_teacher' doesn't exist (SQL: select `teachers`.*, `classes_teacher`.`cla

here is my Classes model

class Classes extends Model
{
   protected $fillable = [
        'name','course_catagory_id','teacher_id'
    ];

    public function coursecatagory()
    {
        return $this->belongsTo(CourseCatagory::class);
    }
    public function teacher()
    {
        return $this->belongsToMany(Teacher::class);
    }
}

and migrations

public function up()
    {
        Schema::create('classes', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('name');
            $table->integer('course_catagory_id');
            $table->integer('teacher_id');
            
            $table->timestamps();
        });
    }

and create classes page

  <div class="card-body">
            @if(session()->has('success'))
             <div class="alert alert-success">
                 
               </div>
             @endif
            <form method="POST" action="">
               @csrf 
               
            <table class="table table-boreder">
               <tr>
                  <th>Name</th>
                  <td>
                     <input type="text" name="name" class="form-control">
                  </td>
               </tr>
               <tr>
                  <td colspan="2">
                     <input type="submit" value="submit" class="btn btn-primary ">
                     
                  </td>
               </tr>
                                  
               </table>
          </form>
            </div>
          </div>

and classes index page

<div class="card-body">
        @if($data->count()>0)
        <table class="table">
            <thead>
                <th>name</th>
                <th>Course Catagory</th>
                <th>
                    Teacher
                </th>
            </thead>
            <tbody>
                @foreach($data as $d)
                <tr>
                    
                    <td>
                        

                    </td>
                    <td>
                        

                    </td>
                    
                    
                    <td>
                    <a href="#">
                        
                    </a>
                    </td>
            
                    
                </tr>
                @endforeach
            </tbody>
        </table>
        @else
        <h3 class="text-center">No class Yet!</h3>
        @endif
        
    </div>

and when i create a new class it saved in the database but dose not restricted to the index view and when i tray to see the index view only the class name is displayed the other fields are not dispalyed and the error face the error



via Chebli Mohamed

Need to update db immediately any changes in response of third party api occurs

I am using third party api,just passing required parameters and getting response.In this case I need to check response in every minute and based on it doing some operations.

For Example:- if request status on third party updated for 1000 rows then it should update my db's 1000 rows simultaneously.

I can set cronjob for this scenerio. But I need some better solution if any changes occur in third party api response then automatically db operations will perform instantly.



via Chebli Mohamed

lundi 3 janvier 2022

How to make a feature request send and cancel system like Uber in Laravel?

  • Admin has a list of requests.
  • When he wants to assign a request a loop run through a rider list
  • The first rider will get a notification. A rider can accept/reject requests.
  • If a rider rejects the request I have to get back to the loop and send a notification to the next rider.
  • If a rider accepts a request he will get 24 hours for a complete request.
  • If a rider does not complete a request within 24 hours I have to get back to the loop and send the request to the next rider.
  • If a rider submits a request on time the request will be closed.
  • *condition If a rider rejects a request this particular rider won’t get a notification for this request next time.


via Chebli Mohamed

How to redirect from rules with no old values laravel

So i know it's weird and but I'm trying to make custom validation rule in laravel for a password so that the new password can't be the same as the old one when i try to change my password but I want to empty the fields when i redirect back so i don't want any old values for security purposes to fill the inputs for that exact validation only but the others can redirect back and fill the old values easily so how can I do that with the custom rules



via Chebli Mohamed

samedi 1 janvier 2022

Argument #1 ($content) must be of type ?string, Illuminate\Routing\Redirector given

i got this error when i load any get url or login or register it gives this error

Symfony\Component\HttpFoundation\Response::setContent(): Argument #1 ($content) must be of type ?string, Illuminate\Routing\Redirector given, called in C:\xampp\htdocs\App\core\vendor\laravel\framework\src\Illuminate\Http\Response.php on line 72

laravel 8 any resolve here



via Chebli Mohamed

Class 'MongoDB\Driver\Manager' not found - Library already loaded

I have spent about 3 days solving this problem and still have not found the solution. I use messenger/mongodb, this is the detail.

"jenssegers/agent": "^2.6", "jenssegers/mongodb": "3.6", "mongodb/mongodb": "1.9.0"

i use PHP 7.4 i check on phpinfo() the MongoDB library already loaded.

enter image description here

I am using macos bigsur on my local mechice.



via Chebli Mohamed