0

I want to insert some data into the DB like this via Eloquent:

public function postDarkhast(Request $request)
    {
        RequestTable::create([
            'course_name' => 1,
            'course_start' => 2,
            'course_end' => 3,
            'course_sessions' => 4,
            'course_time' => 5,
            'course_members' => 6,
            'course_mentor' => 7,
            'course_samaneh' => 8,
        ]);
        
        Session::flash('darkhastSubmitted','Request submitted');
        
        return redirect()->back();
    }

But I don't know why I get this error:

parse_url() expects parameter 1 to be string, array given

I don't know where this parse_url() comes from and the reason behind this error.

So if you know, please help me out solving this issue?

Here is also the Model RequestTable:

class RequestTable extends Model
{
    protected $table = "requests";
    protected $guarded = [];
}

And the fields of requests table has this config:

varchar(191)    utf8_general_ci   NULL

UPDATE #1:

I put the RequestTable::create([...]); in a Try.. Catch and this error return:

enter image description here

Pouya
  • 114
  • 1
  • 8
  • 36
  • can you share the your modal code, I wanna make sure that have added guarded? – Mitesh Rathod Sep 14 '22 at 06:14
  • @MiteshRathod I just added it, please revisit the question – Pouya Sep 14 '22 at 06:15
  • your code looks workable!!! after redirection in which function call? – Mitesh Rathod Sep 14 '22 at 06:19
  • @MiteshRathod The return redirect()->back(); does not execute. I put the RequestTable::create([...]); in a Try.. Catch and the result is **#message: "parse_url() expects parameter 1 to be string, array given"** – Pouya Sep 14 '22 at 06:22
  • @MiteshRathod I just updated the question and added a capture of screen – Pouya Sep 14 '22 at 06:24
  • Did you try replace `return redirect()->back()` to `return back();`? – Dmitry Leiko Sep 14 '22 at 07:35
  • 1
    It looks like you are importing a different `Request`, Have you imported Request at the top like: `use Illuminate\Http\Request;` ? I believe you are importing this `use Symfony\Component\HttpFoundation\Request;` instead. – Akmal Arzhang Sep 14 '22 at 08:20

1 Answers1

0

It looks like you are importing theRequest from Symfony's HttpFoundation instead of Illuminate. Please try importing the Request at the top like: use Illuminate\Http\Request;.

Looking at your error, I believe you are importing the Symfony\Component\HttpFoundation\Request instead.

Akmal Arzhang
  • 357
  • 4
  • 14
  • Your code seems fine than, there should be an issue in a different part. Can I see your controller and model code fully? Or at least the parts you are importing these. – Akmal Arzhang Sep 14 '22 at 09:39