1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

bladeで自作関数を使う方法

Posted at

クラスの作成

モデル.phpに定義する
app/Model.php
    public function 自作関数()
    {
        
    $artists = $this->artist()->get();
    foreach ($artists as $artist){}
        
    return $artist->user_id;
        
    }

bladeテンプレートで使う

blade.php
@if(Auth::id() === $workEdit->自作関数())

{!! Form::model($workEdit, ['route' => ['artist.destroy', $workEdit->id], 'method' => 'delete']) !!}
    {!! Form::submit('作品を削除', ['class' => 'btn btn-danger','onclick' => 'delete_alert(event);return false;']) !!}
{!! Form::close() !!} 
            
@endif

モデルのphpに関数を指定しておけば、blade上でそのモデルを操作する時は、そのまま関数を呼び出して使える。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?