Merge branch '12-duplicate-qrcode' into 'bump-php84'

Resolve "Dupliquer un QR Code"

See merge request ldc-web/projets/qrcollector/qrcollector-back!18
This commit is contained in:
noah.lancien 2026-04-08 13:10:39 +00:00
commit 2c86d0094e
7 changed files with 848 additions and 7 deletions

3
.husky/commit-msg Normal file
View file

@ -0,0 +1,3 @@
#!/bin/sh
npx --no -- commitlint --config node_modules/@uwil/husky-config/commitlint.config.cjs --edit $1

View file

@ -9,8 +9,10 @@ use App\Models\Brand;
use App\Models\Url;
use App\Models\UrlHistory;
use Illuminate\Http\Request;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
use Uwil\LaravelCommon\Helpers\FileHelper;
class UrlController extends Controller
{
@ -48,12 +50,14 @@ class UrlController extends Controller
/**
* Show the form for creating a new resource.
*
* @param \App\Models\Url $url
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
*/
public function create()
public function create(Url $url)
{
return view('bo.pages.urls.create', [
'brands' => Brand::all()
'brands' => Brand::all(),
'urlModel' => $url
]);
}
@ -68,6 +72,18 @@ class UrlController extends Controller
return DB::transaction(function () use ($request) {
$url = new Url();
$url->fill($request->validated());
// When duplicated, $url->logo is the path of the logo from the original model.
$url->logo = is_string($url->logo) ?
new UploadedFile(
FileHelper::getPublicAbsolutePath($url->logo),
sprintf(
'%s.%s',
Str::uuid(),
new \SplFileInfo(asset($url->logo))->getExtension()
)) :
$url->logo;
$url->saveOrFail();
// Reassign the logo in image settings to save only the path.
@ -168,6 +184,20 @@ class UrlController extends Controller
->with(['warning' => 'L\'url pour la clé ' . $url->key . ' a bien été supprimée.']);
}
/**
* Duplicate the specified resource.
*
* @param \App\Models\Url $url
* @return \Illuminate\Contracts\View\View
*/
public function duplicate(Url $url): \Illuminate\Contracts\View\View
{
$duplicatedUrl = $url->replicate(['key']);
return $this->create($duplicatedUrl);
}
/**
* Save url history when updating url.
* @param Url $url

1
commitlint.config.cjs Normal file
View file

@ -0,0 +1 @@
module.exports = require('@uwil/husky-config/commitlint.config.cjs');

809
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -31,6 +31,7 @@
"@types/toastify-js": "^1.12.4",
"@typescript-eslint/eslint-plugin": "^5.62.0",
"@typescript-eslint/parser": "^5.36.2",
"@uwil/husky-config": "^1.0.1",
"@vitejs/plugin-basic-ssl": "^1.0.1",
"@vitejs/plugin-vue": "^4.6.2",
"@vue/eslint-config-typescript": "^11.0.3",

View file

@ -9,7 +9,7 @@
'model' => $urlModel ?? null,
'helper' => __('La clé sera visible dans l\'url obtenue en scannant le QRCode. Doit être au format slug (ou sera transformée si ce n\'est pas le cas).'),
'placeholder' => "XXX",
'disabled' => $urlModel ?? false
'disabled' => $urlModel->exists ?? false
])
</div>
<div class="col-12">

View file

@ -39,6 +39,11 @@ Route::prefix('bo')
// Urls routes.
Route::resource('/urls', UrlController::class);
Route::get('/urls/{url}/duplicate', [
UrlController::class,
'duplicate'
])->name('urls.duplicate');
// Services routes.
Route::resource('/services', ServiceController::class)->except('show');