Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

451
Visualizações
Can I have a Laravel Model without a database table?

I would like to have a Laravel Model with all of the features and functions of a Laravel Model, but the data for the model is completely static and will never change. I could create a database table for it, but that leaves the possibility of someone modifying the table directly.

For example:

    //  Model Data for Log Levels
    name      | icon                | color
    -------------------------------------------
    Emergency | fas fa-ambulance    | red
    Alert     | fas fa-bullhorn     | yellow
    Critical  | fas fa-heartbeast   | orange
    ....

This would be the data, stored in the model file the same as if it was a DB table, but can never be changed. Is this possible?

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

You can use Sushi for that.

Eloquent's missing "array" driver.

Sometimes you want to use Eloquent, but without dealing with a database.

class State extends Model
{
    use \Sushi\Sushi;

    protected $rows = [
        [
            'name' => 'Emergency',
            'icon' => 'fas fa-ambulance',
            'color' => 'red'
        ],
        [
            'name' => 'Alert',
            'icon' => 'fas fa-bullhorn',
            'color' => 'yellow'
        ],
        [
            'name' => 'Critical',
            'icon' => 'fas fa-heartbeast',
            'color' => 'orange'
        ],
    ];
}

https://github.com/calebporzio/sushi

over 4 years ago · Santiago Trujillo Relatório

0

I think you can use a simple model, without creating forms for injecting data, and a seeder to inculde your data at first time (when you run migrate).

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda