Question: I have a method that receives some data from a 3rd party. The data is a JSON object (not a string, I tried receiving as a string and data was not accessable - the data property was null)

```
[HttpPost]
 [Route("com/sendemail")]
 public async Task<IActionResult> SendEmail(dynamic data)
 {
       mailData = JsonConvert.DeserializeObject<EmailTemplate>(data);
 }

```

I am trying to get it into a .net object which is needed to be passed into another function I dont control. It has to be an EmailTemplate object, which is defined as:

```
public class EmailTemplate
{
        public string From { get; set; }
        public string To { get; set; }
        public string Subject { get; set; }
        public string EmailHtml { get; set; }
}

```

mailData is of type EmailTemplate. The Deserialize object call fails because that method requires a string, which this isnt. Ive tried other methods, such as

```
mailData = (EmailTemplate)data;

```

and

```
mailData.To = data.To

```

but neither work. Any pointers gratefully received.

PS. Heres what the data looks like in visual studio

[![enter image description here](https://i.stack.imgur.com/xlCQM.png)](https://i.stack.imgur.com/xlCQM.png)

Answer: 
You can do that by saving the `Patient` object in a variable when creating it:

```
public function store(Request $request)
    {
        $input = request()->all();
        $patient = Patient::create($input); // Save it in variable
        dd($patient->id); //Now you can access patient id here
        // return redirect()->route('medical.create',compact('patient')); //Also you can pass it to your view

    }

```
You can't use compact while redirecting. Try this:

Patient Controller:

```
 public function store(Request $request)
    {

        $input = request()->all();
        $patient = Patient::create($input);
        $patient = DB::table('patients')->get()->last();
        return redirect()->route('medical.create')->with('patient_id', $patient->id);

    }

```

This is my medical.create view

```
{!! Form::model($input, [
    'method' => 'POST',
    'action' => ['MedicalController@store', session('patient_id')]
]) !!}
        <div class="row">
                <div class="col-md-4">

                        <div class="form-group">
                        {{Form::label('patient_id','Patient no:')}}
                        {{Form::text('patient_id', null, array('class' => 'form-control') )}}
                        </div>

                </div>

        </div>

             {!! Form::close() !!}

```