Olá a todos, sou novo na área de multimídia. Estou a seguir a um momento um ebook sobre a criação de uma base de dados e também a criação de tabelas. Mas quando vinculei as tabelas do banco de dados, no phpmyadmin me deu alguns erros. Fiz a correspondência da chave primária (artist_id da tabela Artist) com a artist_id da tabela Prints (chave estrangeira) e assim por diante. O problema é que ele não mostra minhas relações das tabelas e me dá uma mensagem de erro. Então, alguns de vocês poderiam me ajudar, por favor, a consertar esta situação. Eu serei grato. Cumprimentos.
Ps .: Abaixo envio o arquivo Sql.
Atentamente,
José Moreira
-- phpMyAdmin SQL Dump
-- version 5.0.2
-- https://www.phpmyadmin.net/
--
-- Host: 127.0.0.1
-- Generation Time: Jan 07, 2021 at 08:49 PM
-- Server version: 10.4.14-MariaDB
-- PHP Version: 7.2.33
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
START TRANSACTION;
SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
--
-- Database: `ecommerce`
--
-- --------------------------------------------------------
--
-- Table structure for table `artists`
--
CREATE TABLE `artists` (
`artist_id` int(10) UNSIGNED NOT NULL,
`first_name` varchar(20) DEFAULT NULL,
`middle_name` varchar(20) DEFAULT NULL,
`last_name` varchar(40) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;
-- --------------------------------------------------------
--
-- Table structure for table `customers`
--
CREATE TABLE `customers` (
`customer_id` int(10) UNSIGNED NOT NULL,
`email` varchar(60) NOT NULL,
`pass` char(40) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;
-- --------------------------------------------------------
--
-- Table structure for table `orders`
--
CREATE TABLE `orders` (
`order_id` int(10) UNSIGNED NOT NULL,
`customer_id` int(10) UNSIGNED NOT NULL,
`total` decimal(10,2) UNSIGNED NOT NULL,
`order_date` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
-- --------------------------------------------------------
--
-- Table structure for table `order_contents`
--
CREATE TABLE `order_contents` (
`oc_id` int(10) UNSIGNED NOT NULL,
`order_id` int(10) UNSIGNED NOT NULL,
`print_id` int(10) UNSIGNED NOT NULL,
`quantity` tinyint(3) UNSIGNED NOT NULL DEFAULT 1,
`price` decimal(6,2) UNSIGNED NOT NULL,
`ship_date` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
-- --------------------------------------------------------
--
-- Table structure for table `prints`
--
CREATE TABLE `prints` (
`print_id` int(10) UNSIGNED NOT NULL,
`artist_id` int(10) UNSIGNED NOT NULL,
`print_name` varchar(60) NOT NULL,
`price` decimal(6,2) UNSIGNED NOT NULL,
`size` varchar(60) DEFAULT NULL,
`description` varchar(255) DEFAULT NULL,
`image_name` varchar(60) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;
--
-- Indexes for dumped tables
--
--
-- Indexes for table `artists`
--
ALTER TABLE `artists`
ADD PRIMARY KEY (`artist_id`),
ADD UNIQUE KEY `full_name` (`last_name`,`first_name`,`middle_name`);
--
-- Indexes for table `customers`
--
ALTER TABLE `customers`
ADD PRIMARY KEY (`customer_id`),
ADD UNIQUE KEY `email` (`email`),
ADD KEY `login` (`email`,`pass`);
--
-- Indexes for table `orders`
--
ALTER TABLE `orders`
ADD PRIMARY KEY (`order_id`),
ADD KEY `customer_id` (`customer_id`),
ADD KEY `order_date` (`order_date`);
--
-- Indexes for table `order_contents`
--
ALTER TABLE `order_contents`
ADD PRIMARY KEY (`oc_id`),
ADD KEY `order_id` (`order_id`),
ADD KEY `print_id` (`print_id`),
ADD KEY `ship_date` (`ship_date`);
--
-- Indexes for table `prints`
--
ALTER TABLE `prints`
ADD PRIMARY KEY (`print_id`),
ADD KEY `artist_id` (`artist_id`),
ADD KEY `print_name` (`print_name`),
ADD KEY `price` (`price`);
--
-- AUTO_INCREMENT for dumped tables
--
--
-- AUTO_INCREMENT for table `artists`
--
ALTER TABLE `artists`
MODIFY `artist_id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT for table `customers`
--
ALTER TABLE `customers`
MODIFY `customer_id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT for table `orders`
--
ALTER TABLE `orders`
MODIFY `order_id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT for table `order_contents`
--
ALTER TABLE `order_contents`
MODIFY `oc_id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT for table `prints`
--
ALTER TABLE `prints`
MODIFY `print_id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT;
COMMIT;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
Eu tenho uma rotina que faz uma leitura do arquivo .xml de vários sites.
Eu consigo pegar o tópico e a descrição, e mostrar a imagem que esta na pagina do link.
Para isso utilizo esta função:
function getPreviewImage($url) {
// Obter o conteúdo da página
$html = file_get_contents($url);
// Criar um novo objeto DOMDocument
$doc = new DOMDocument();
@$doc->loadHTML($html);
// Procurar pela tag meta og:image
$tags = $doc->getElementsByTagName('meta');
foreach ($tags as $tag) {
if ($tag->getAttribute('property') == 'og:image') {
return $tag->getAttribute('content');
}
}
// Se não encontrar og:image, procurar pela primeira imagem na página
$tags = $doc->getElementsByTagName('img');
if ($tags->length > 0) {
return $tags->item(0)->getAttribute('src');
}
// Se não encontrar nenhuma imagem, retornar null
return null;
}
// Uso:
$url = "https://example.com/article";
$imageUrl = getPreviewImage($url);
if ($imageUrl) {
echo "<img src='$imageUrl' alt='Preview'>";
} else {
echo "Nenhuma imagem encontrada";
}
Mas estou com um problema, esta funcão funciona quando coloco em uma pagina de teste.php. Preciso mostrar em uma página inicial diversas fotos de todos os links. (No caso acima só funciona 1).
Tenho uma abela de usuarios e uma tabela de administradores e clientes.
Gostaria de uma ajuda para implementar um cadastro
users -> name, login, passord (pronta)
admins -> user_id, registratiom, etc..
client -> user_id, registratiom, etc...
Queria ajuda para extender de user as classes Admin e Client
Olhem como estáAdmin
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Admin extends User
{
use HasFactory;
protected $fillable = [
'name',
'email',
'password',
'registration'
];
private string $registration;
public function create(
string $name,
string $email,
string $password,
string $registration
)
{
//parent::create(['name'=>$name, 'email'=>$email, 'password'=>$password]);
parent::$name = $name;
parent::$email = $email;
parent::$password = $password;
$this->registration = $registration;
}
}
User
<?php
namespace App\Models;
// use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
class User extends Authenticatable
{
/** @use HasFactory<\Database\Factories\UserFactory> */
use HasFactory, Notifiable;
static string $name;
static string $email;
static string $password;
/**
* The attributes that are mass assignable.
*
* @var list<string>
*/
protected $fillable = [
'name',
'email',
'password',
];
/**
* The attributes that should be hidden for serialization.
*
* @var list<string>
*/
protected $hidden = [
'remember_token',
];
/**
* Get the attributes that should be cast.
*
* @return array<string, string>
*/
protected function casts(): array
{
return [
'email_verified_at' => 'datetime',
'password' => 'hashed',
];
}
public function roles() : BelongsToMany {
return $this->belongsToMany(Role::class);
}
public function hasHole(Array $roleName): bool
{
foreach ($this->roles as $role) {
if ($role->name === $roleName) {
return true;
}
}
return false;
}
public function hasHoles(Array $rolesName): bool
{
foreach ($this->roles as $role) {
foreach ($rolesName as $rolee) {
if ($role->name === $rolee) {
return true;
}
}
}
return false;
}
public function hasAbility(string $ability): bool
{
foreach ($this->roles as $role) {
if ($role->abilities->contains('name', $ability)) {
return true;
}
}
return false;
}
}
Como gravar um Admin na tabela admins sendo que ele é um User por extensão?
Tentei assim mas é claro que está errado...
public function store(Request $request, Admin $adminModel) {
$dados = $request->validate([
"name" => "required",
"email" => "required|email",
"password" => "required",
"registration" => "required"
]);
$dados["password"] = Hash::make($dados["password"]);
$admin = Admin::where("registration", $dados["registration"])->first();
if ($admin)
return
redirect()->route("admin.new")
->withErrors([
'fail' => 'Administrador já cadastrados<br>, favor verificar!'
]);
$newAdmin = $adminModel->create(
$dados['name'],
$dados['email'],
$dados['password'],
$dados['registration']
);
dd($newAdmin);
$adminModel->save();
//$adminModel::create($admin);
return redirect()->route("admin.new")->with("success",'Cadastrado com sucesso');
}
Gostaria de tirar uma dúvida com os amigos, referente a PDV.
Estou escrevendo um Sistema com Ponto de Vendas, a minha dúvida é o seguinte, referente ao procedimento mais correto.
Conforme o caixa vai efetuando a venda, o Sistema de PDV já realiza:
a baixa direto dos produtos no estoque
ou
somente após concretizar a venda o sistema baixa os produtos do estoque ?
Estou com uma pequena dúvida referente a Teclas de Atalho.
Quando o Caps Lock está ativado o Comando da Tecla de Atalho não funciona.
ou seja:
se estiver para letra minúscula ====> funciona
se estiver para letra maiúscula ====> não funciona
Como consigo evitar essa falha, tanto para Letra Maiúscula quanto Minúscula ?
o Código está assim:
document.addEventListener( 'keydown', evt => {
if (!evt.ctrlKey || evt.key !== 'r' )
return;// Não é Ctrl+r, portanto interrompemos o script
evt.preventDefault();
});
Grato,
Olá a todos, sou novo na área de multimídia. Estou a seguir a um momento um ebook sobre a criação de uma base de dados e também a criação de tabelas. Mas quando vinculei as tabelas do banco de dados, no phpmyadmin me deu alguns erros. Fiz a correspondência da chave primária (artist_id da tabela Artist) com a artist_id da tabela Prints (chave estrangeira) e assim por diante. O problema é que ele não mostra minhas relações das tabelas e me dá uma mensagem de erro. Então, alguns de vocês poderiam me ajudar, por favor, a consertar esta situação. Eu serei grato. Cumprimentos.
Ps .: Abaixo envio o arquivo Sql.
Atentamente,
José Moreira
Compartilhar este post
Link para o post
Compartilhar em outros sites