企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
# 模型 # 模型 快捷方式创建模型: ``` <pre class="calibre13">``` php artisan make<span class="token1">:</span>model Test ``` ``` 模型里面的代码: ``` <pre class="calibre13">``` <span class="token"><</span><span class="token">?</span>php namespace App\Models<span class="token1">;</span> use Illuminate\Database\Eloquent\Factories\HasFactory<span class="token1">;</span> use Illuminate\Database\Eloquent\Model<span class="token1">;</span> <span class="token2">class</span> <span class="token3">Test</span> <span class="token2">extends</span> <span class="token3">Model</span> <span class="token1">{</span> use HasFactory<span class="token1">;</span> <span class="token2">public</span> <span class="token2">static</span> <span class="token2">function</span> <span class="token3">getName</span><span class="token1">(</span><span class="token1">)</span><span class="token1">{</span> <span class="token2">return</span> <span class="token4">'这是模型里面的name'</span><span class="token1">;</span> <span class="token1">}</span> <span class="token1">}</span> ``` ``` 控制器里面调用: ``` <pre class="calibre13">``` <span class="token"><</span><span class="token">?</span>php namespace App\Http\Controllers<span class="token1">;</span> use App\Models\Test<span class="token1">;</span> use Illuminate\Http\Request<span class="token1">;</span> <span class="token2">class</span> <span class="token3">TestController</span> <span class="token2">extends</span> <span class="token3">Controller</span> <span class="token1">{</span> <span class="token2">public</span> <span class="token2">function</span> <span class="token3">abc</span><span class="token1">(</span><span class="token1">)</span><span class="token1">{</span> <span class="token2">return</span> Test<span class="token1">:</span><span class="token1">:</span><span class="token3">getName</span><span class="token1">(</span><span class="token1">)</span><span class="token1">;</span> <span class="token2">return</span> <span class="token3">view</span><span class="token1">(</span><span class="token4">'info'</span><span class="token1">,</span><span class="token1">[</span> <span class="token4">'name'</span><span class="token">=></span><span class="token4">'测试账号'</span><span class="token1">,</span> <span class="token4">'age'</span> <span class="token">=></span> <span class="token5">28</span> <span class="token1">]</span><span class="token1">)</span><span class="token1">;</span> <span class="token1">}</span> <span class="token1">}</span> ``` ``` 访问:<http://la.com/info> 输出: 这是模型里面的name