D
D
Dom Alfro2021-05-27 19:29:34
Laravel
Dom Alfro, 2021-05-27 19:29:34

Is it possible to pass a dynamic value to find() instead of static ones?

I'm probably not reading the documentation correctly, since I can't find the answer to the question.
Can you give a direction where to read, or a reference.
Because I can't figure out how to attach an id from one connection to another in the code that I will give below . I use eloquent. (there is an orm/database)
I can statically, but I don’t know how to do it dynamically...
and here is an example

$post = new Post();
          $post->name = $data['name']; // name - данные попадают с input
          $post->save(); // сохранить

          $image = new Image(
            [
              'img1' => 'это последние данные к нашим постам',
              'img2' => 'данные для последнего поста'
            ]          
          );

        $stmt = Image::find(2)->image; // image метод модели image
          echo "<pre>";
          dd($stmt);
          $post->image()->save($image);
// если Image::find(2) то так сохраняются данные но мне нужно что бы в find значение приходило динамически, что я только не пробовал уже...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya, 2021-05-28
@mustang_shelby

$latestImage = Image::orderByDesc('id')->first();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question